整合 JSF+Spring+Hibernate的小例子

(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();
}


}

(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 >

(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;

}

(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();
}

}

(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;
}

(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);
}

}

(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;
}

}

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()...{
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值