|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
java比较简单,没有C++的烦琐,但学习时最好有C++为基础.与JSP和SQL起应用,功能强大.创立
/**Createdon2005-4-21*/packageorg.appfuse.model;
importorg.apache.commons.lang.builder.EqualsBuilder;importorg.apache.commons.lang.builder.HashCodeBuilder;importorg.apache.commons.lang.builder.ToStringBuilder;
/***@hibernate.classtable="person"*/publicclassPersonextendsBaseObject{
privateLongid;
privateStringfirstName;
privateStringlastName;
/***@returnReturnsthefirstName.*@hibernate.propertycolumn="first_name"length="50"*/publicStringgetFirstName(){returnfirstName;}
/***@paramfirstName*ThefirstNametoset.*/publicvoidsetFirstName(StringfirstName){this.firstName=firstName;}
/***@returnReturnstheid.*@hibernate.idcolumn="id"generator-class="native"unsaved-value="null"*/publicLonggetId(){returnid;}
/***@paramid*Theidtoset.*/publicvoidsetId(Longid){this.id=id;}
/***@returnReturnsthelastName.*@hibernate.propertycolumn="last_name"length="50"*/publicStringgetLastName(){returnlastName;}
/***@paramlastName*ThelastNametoset.*/publicvoidsetLastName(StringlastName){this.lastName=lastName;}
/***@seejava.lang.Object#equals(Object)*/publicbooleanequals(Objectobject){if(!(objectinstanceofPerson)){returnfalse;}Personrhs=(Person)object;returnnewEqualsBuilder().append(this.firstName,rhs.firstName).append(this.id,rhs.id).append(this.lastName,rhs.lastName).isEquals();}/***publicbooleanequals(Objectobject){if(!(objectinstanceofAddress)){returnfalse;}
Addressrhs=(Address)object;
returnnewEqualsBuilder().append(this.postalCode,rhs.postalCode).append(this.country,rhs.country).append(this.address,rhs.address).append(this.province,rhs.province).append(this.city,rhs.city).isEquals();}*//***@seejava.lang.Object#hashCode()*/publicinthashCode(){returnnewHashCodeBuilder(-1196181247,-1232855255).append(this.firstName).append(this.id).append(this.lastName).toHashCode();}
/***@seejava.lang.Object#toString()*/publicStringtoString(){returnnewToStringBuilder(this).append("lastName",this.lastName).append("id",this.id).append("firstName",this.firstName).toString();}}
##############################################################packageorg.appfuse.dao;
importorg.appfuse.model.Person;importorg.springframework.dao.DataAccessException;
publicclassPersonDAOTestextendsBaseDAOTestCase{//一个基础的初始化、烧毁PersonDAO对象的Junit测试privatePersonperson=null;
privatePersonDAOdao=null;
protectedvoidsetUp()throwsException{super.setUp();dao=(PersonDAO)ctx.getBean("personDAO");}
//"ctx"对象是对Spring的ApplicationContext的一个援用,它在BaseDAOTestCases//类的静态代码块中被初始化。protectedvoidtearDown()throwsException{super.tearDown();dao=null;}
//-----------------------------------------------------------------------------------------------------------------------------publicvoidtestGetPerson()throwsException{person=newPerson();person.setFirstName("Matt");person.setLastName("Raible");
dao.savePerson(person);assertNotNull(person.getId());
person=dao.getPerson(person.getId());assertEquals(person.getFirstName(),"Matt");}
publicvoidtestSavePerson()throwsException{person=dao.getPerson(newLong(1));person.setFirstName("Matt");
person.setLastName("LastNameUpdated");
dao.savePerson(person);
if(log.isDebugEnabled()){log.debug("updatedPerson:"+person);}
assertEquals(person.getLastName(),"LastNameUpdated");}
publicvoidtestAddAndRemovePerson()throwsException{person=newPerson();person.setFirstName("Bill");person.setLastName("Joy");
dao.savePerson(person);
assertEquals(person.getFirstName(),"Bill");assertNotNull(person.getId());
if(log.isDebugEnabled()){log.debug("removingperson...");}
dao.removePerson(person.getId());
try{person=dao.getPerson(person.getId());fail("Personfoundindatabase");}catch(DataAccessExceptiondae){log.debug("Expectedexception:"+dae.getMessage());assertNotNull(dae);}}
}
首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。 |
|