(1)UserInfo.java
package
com.zhaoqingjie.service.hibernate;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
public class UserInfo implements Serializable ... {
privateStringid;
privateStringusername;
privateStringemail;
publicUserInfo(Stringid,Stringusername,Stringemail)...{
this.id=id;
this.username=username;
this.email=email;
}
publicUserInfo()...{
}
publicUserInfo(Stringid)...{
this.id=id;
}
publicStringgetId()...{
returnid;
}
publicvoidsetId(Stringid)...{
this.id=id;
}
publicStringgetEmail()...{
returnemail;
}
publicvoidsetEmail(Stringemail)...{
this.email=emial;
}
publicStringgetUsername()...{
returnusername;
}
publicvoidsetUsername(Stringusername)...{
this.username=username;
}
publicStringtoString()...{
returnnewToStringBuilder(this).append("id",getId()).toString();
}
}
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
public class UserInfo implements Serializable ... {
privateStringid;
privateStringusername;
privateStringemail;
publicUserInfo(Stringid,Stringusername,Stringemail)...{
this.id=id;
this.username=username;
this.email=email;
}
publicUserInfo()...{
}
publicUserInfo(Stringid)...{
this.id=id;
}
publicStringgetId()...{
returnid;
}
publicvoidsetId(Stringid)...{
this.id=id;
}
publicStringgetEmail()...{
returnemail;
}
publicvoidsetEmail(Stringemail)...{
this.email=emial;
}
publicStringgetUsername()...{
returnusername;
}
publicvoidsetUsername(Stringusername)...{
this.username=username;
}
publicStringtoString()...{
returnnewToStringBuilder(this).append("id",getId()).toString();
}
}
(2)UserInfo.hbm.xml
<?
xmlversion="1.0"
?>
<! DOCTYPEhibernate-mappingPUBLIC
"-//Hibernate/HibernateMappingDTD2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
< hibernate-mapping >
< class name ="com.zhaoqingjie.spring.service.hibernate.UserInfo" table ="userinfo" >
< meta attribute ="class-description" inherit ="false" >
@hibernate.class
table="userinfo"
</ meta >
< id name ="id" type ="java.lang.String" column ="id" >
< meta attribute ="field-description" >
@hibernate.id
generator-class="assigned"
type="java.lang.String"
column="id"
</ meta >
< generator class ="assigned" />
</ id >
< property name ="username" type ="java.lang.String" column ="username" length ="36" >
< meta attribute ="field-description" >
@hibernate.property
column="username"
length="36"
</ meta >
</ property >
< property name ="email" type ="java.lang.String" column ="email" length ="60" >
< meta attribute ="field-description" >
@hibernate.property
column="email"
length="60"
</ meta >
</ property >
</ class >
</ hibernate-mapping >
<! DOCTYPEhibernate-mappingPUBLIC
"-//Hibernate/HibernateMappingDTD2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
< hibernate-mapping >
< class name ="com.zhaoqingjie.spring.service.hibernate.UserInfo" table ="userinfo" >
< meta attribute ="class-description" inherit ="false" >
@hibernate.class
table="userinfo"
</ meta >
< id name ="id" type ="java.lang.String" column ="id" >
< meta attribute ="field-description" >
@hibernate.id
generator-class="assigned"
type="java.lang.String"
column="id"
</ meta >
< generator class ="assigned" />
</ id >
< property name ="username" type ="java.lang.String" column ="username" length ="36" >
< meta attribute ="field-description" >
@hibernate.property
column="username"
length="36"
</ meta >
</ property >
< property name ="email" type ="java.lang.String" column ="email" length ="60" >
< meta attribute ="field-description" >
@hibernate.property
column="email"
length="60"
</ meta >
</ property >
</ class >
</ hibernate-mapping >
(3)IUserInfoDAO.java
package
com.zhaoqingjie.spring.service.dao;
import com.openv.spring.domainmodel.UserInfoVO;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
public interface IUserInfoDAO extends Serializable ... {
publicbooleansetUserInfo(UserInfoVOuserinfoVO)throwsDataAccessException;
}
import com.openv.spring.domainmodel.UserInfoVO;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
public interface IUserInfoDAO extends Serializable ... {
publicbooleansetUserInfo(UserInfoVOuserinfoVO)throwsDataAccessException;
}
(4)UserInfoDAO.java
package
com.zhaoqingjie.spring.service.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.doomdark.uuid.UUIDGenerator;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.zhaoqingjie.spring.domainmodel.UserInfoVO;
import com.zhaoqingjie.spring.service.dao.IUserInfoDAO;
import com.zhaoqingjie.spring.service.hibernate.UserInfo;
public class UserInfoDAO extends HibernateDaoSupport implements IUserInfoDAO ... {
privatestaticfinalLoglog=LogFactory.getLog(UserInfoDAO.class);
publicbooleansetUserInfo(UserInfoVOuserinfoVO)throwsDataAccessException...{
if(userinfoVO==null)...{
returnfalse;
}
UserInfoui=newUserInfo();
ui.setId(getID());
ui.setUsername(userinfoVO.getUsername().trim());
ui.setEmail(userinfoVO.getEmail().trim());
this.getHibernateTemplate().save(ui);
returntrue;
}
privateStringgetID()...{
returnUUIDGenerator.getInatance().generateTimeBaseUUID().toString();
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.doomdark.uuid.UUIDGenerator;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.zhaoqingjie.spring.domainmodel.UserInfoVO;
import com.zhaoqingjie.spring.service.dao.IUserInfoDAO;
import com.zhaoqingjie.spring.service.hibernate.UserInfo;
public class UserInfoDAO extends HibernateDaoSupport implements IUserInfoDAO ... {
privatestaticfinalLoglog=LogFactory.getLog(UserInfoDAO.class);
publicbooleansetUserInfo(UserInfoVOuserinfoVO)throwsDataAccessException...{
if(userinfoVO==null)...{
returnfalse;
}
UserInfoui=newUserInfo();
ui.setId(getID());
ui.setUsername(userinfoVO.getUsername().trim());
ui.setEmail(userinfoVO.getEmail().trim());
this.getHibernateTemplate().save(ui);
returntrue;
}
privateStringgetID()...{
returnUUIDGenerator.getInatance().generateTimeBaseUUID().toString();
}
}
(5)IExampleManager.java
package
com.zhaoqingjie.spring.service;
import com.openv.spring.domainmodel.UserInfoVO;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
public interface IExampleManager extends Serializable ... {
publicbooleansetUserInfo(UserInfoVOuserinfoVO)
throwsDataAccessException;
}
import com.openv.spring.domainmodel.UserInfoVO;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
public interface IExampleManager extends Serializable ... {
publicbooleansetUserInfo(UserInfoVOuserinfoVO)
throwsDataAccessException;
}
(6)ExampleManagerImpl.java
package
com.zhaoqingjie.spring.service.impl;
import com.openv.spring.domainmodel.UserInfoVO;
import com.openv.spring.service.IExample29Manager;
import com.openv.spring.service.dao.IUserInfoDAO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
public class ExampleManagerImpl implements IExampleManager ... {
privatestaticfinalLoglog=LogFactory
.getLog(ExampleManagerImpl.class);
privateIUserInfoDAOuserinfo;
publicExampleManagerImpl()...{
log.info("ExampleManagerImpl()...................");
}
publicvoidsetUserinfo(IUserInfoDAOuserinfoDAO)
throwsDataAccessException...{
this.userinfo=userinfoDAO;
}
publicbooleansetUserInfo(UserInfoVOuserinfoVO)
throwsDataAccessException...{
returnuserinfo.setUserInfo(userinfoVO);
}
}
import com.openv.spring.domainmodel.UserInfoVO;
import com.openv.spring.service.IExample29Manager;
import com.openv.spring.service.dao.IUserInfoDAO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
public class ExampleManagerImpl implements IExampleManager ... {
privatestaticfinalLoglog=LogFactory
.getLog(ExampleManagerImpl.class);
privateIUserInfoDAOuserinfo;
publicExampleManagerImpl()...{
log.info("ExampleManagerImpl()...................");
}
publicvoidsetUserinfo(IUserInfoDAOuserinfoDAO)
throwsDataAccessException...{
this.userinfo=userinfoDAO;
}
publicbooleansetUserInfo(UserInfoVOuserinfoVO)
throwsDataAccessException...{
returnuserinfo.setUserInfo(userinfoVO);
}
}
(7)UserInfoVO.java
package
com.zhaoqingjie.spring.domainmodel;
import java.io.Serializable;
public class UserInfoVO implements Serializable ... {
privateStringusername;
privateStringemail;
publicStringgetEmail()...{
returnemail;
}
publicvoidsetEmail(Stringemail)...{
this.email=email;
}
publicStringgetUsername()...{
returnusername;
}
publicvoidsetUsername(Stringusername)...{
this.username=username;
}
}
import java.io.Serializable;
public class UserInfoVO implements Serializable ... {
privateStringusername;
privateStringemail;
publicStringgetEmail()...{
returnemail;
}
publicvoidsetEmail(Stringemail)...{
this.email=email;
}
publicStringgetUsername()...{
returnusername;
}
publicvoidsetUsername(Stringusername)...{
this.username=username;
}
}
JSF表示层
(8)InfoBean.java
package
com.zhaoqingjie.spring.jsf;
import javax.faces.context.FacesContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;
import com.openv.spring.domainmodel.UserInfoVO;
import com.openv.spring.service.IExampleManager;
public class InfoBean ... {
privatestaticfinalLoglog=LogFactory.getLog(InfoBean.class);
privateStringusername=null;
privateStringemail=null;
privateStringresponse=null;
privatelongmaximum=0;
privatebooleanmaximumSet=false;
privatelongminimum=0;
privatebooleanminimumSet=false;
publicInfoBean()...{
}
import javax.faces.context.FacesContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;
import com.openv.spring.domainmodel.UserInfoVO;
import com.openv.spring.service.IExampleManager;
public class InfoBean ... {
privatestaticfinalLoglog=LogFactory.getLog(InfoBean.class);
privateStringusername=null;
privateStringemail=null;
privateStringresponse=null;
privatelongmaximum=0;
privatebooleanmaximumSet=false;
privatelongminimum=0;
privatebooleanminimumSet=false;
publicInfoBean()...{
}