知识大全 整合 JSF+Spring+Hibernate的小例子
Posted 知
篇首语:常识是我所知道的最高的通情达理。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 整合 JSF+Spring+Hibernate的小例子相关的知识,希望对你有一定的参考价值。
整合 JSF+Spring+Hibernate的小例子 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
( )UserInfo java
package zhaoqingjie service hibernate; import java io Serializable; import mons lang builder ToStringBuilder; public class UserInfo implements Serializable private String id; private String username; private String email; public UserInfo(String id String username String email) this id = id; this username = username; this email = email; public UserInfo() public UserInfo(String id) this id = id; public String getId() return id; public void setId(String id) this id = id; public String getEmail() return email; public void setEmail(String email) this email = emial; public String getUsername() return username; public void setUsername(String username) this username = username; public String toString() return new ToStringBuilder(this) append( id getId()) toString();
( )UserInfo hbm xml
<?xml version= ?> <!DOCTYPE hibernate mapping PUBLIC //Hibernate/Hibernate Mapping DTD //EN mapping dtd > <hibernate mapping> <class name= 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= > <meta attribute= field description > @hibernate property column= username length= </meta> </property> <property name= email type= java lang String column= email length= > <meta attribute= field description > @hibernate property column= email length= </meta> </property> </class> </hibernate mapping>
( )IUserInfoDAO java
package zhaoqingjie spring service dao; import openv spring domainmodel UserInfoVO; import springframework dao DataAccessException; import java io Serializable; public interface IUserInfoDAO extends Serializable public boolean setUserInfo(UserInfoVO userinfoVO)throws DataAccessException;
( )UserInfoDAO java
package zhaoqingjie spring service dao impl; import mons logging Log; import mons logging LogFactory; import doomdark uuid UUIDGenerator; import springframework dao DataAccessException; import springframework orm hibernate support HibernateDaoSupport; import zhaoqingjie spring domainmodel UserInfoVO; import zhaoqingjie spring service dao IUserInfoDAO; import zhaoqingjie spring service hibernate UserInfo; public class UserInfoDAO extends HibernateDaoSupport implements IUserInfoDAO private static final Log log = LogFactory getLog(UserInfoDAO class); public boolean setUserInfo(UserInfoVO userinfoVO)throws DataAccessException if(userinfoVO == null) return false; UserInfo ui = new UserInfo(); ui setId(getID()); ui setUsername(userinfoVO getUsername() trim()); ui setEmail(userinfoVO getEmail() trim()); this getHibernateTemplate() save(ui); return true; private String getID() return UUIDGenerator getInatance() generateTimeBaseUUID() toString();
( )IExampleManager java
package zhaoqingjie spring service; import openv spring domainmodel UserInfoVO; import springframework dao DataAccessException; import java io Serializable; public interface IExampleManager extends Serializable public boolean setUserInfo(UserInfoVO userinfoVO) throws DataAccessException;
( )ExampleManagerImpl java
package zhaoqingjie spring service impl; import openv spring domainmodel UserInfoVO; import openv spring service IExample Manager; import openv spring service dao IUserInfoDAO; import mons logging Log; import mons logging LogFactory; import springframework dao DataAccessException; public class ExampleManagerImpl implements IExampleManager private static final Log log = LogFactory getLog(ExampleManagerImpl class); private IUserInfoDAO userinfo; public ExampleManagerImpl() ( ExampleManagerImpl() ); public void setUserinfo(IUserInfoDAO userinfoDAO) throws DataAccessException this userinfo = userinfoDAO; public boolean setUserInfo(UserInfoVO userinfoVO) throws DataAccessException return userinfo setUserInfo(userinfoVO);
( )UserInfoVO java
package zhaoqingjie spring domainmodel; import java io Serializable; public class UserInfoVO implements Serializable private String username; private String email; public String getEmail() return email; public void setEmail(String email) this email = email; public String getUsername() return username; public void setUsername(String username) this username = username;
JSF表示层 ( )InfoBean java
package zhaoqingjie spring jsf; import ntext FacesContext; import mons logging Log; import mons logging LogFactory; import ntext ApplicationContext; import springframework web jsf FacesContextUtils; import openv spring domainmodel UserInfoVO; import openv spring service IExampleManager; public class InfoBean private static final Log log = LogFactory getLog(InfoBean class); private String username = null; private String email = null; private String response = null; private long maximum = ; private boolean maximumSet = false; private long minimum = ; private boolean minimumSet = false; public InfoBean() public String getEmail() return email; public void setEmail(String email) this email = email; public String getUsername() return username; public void setUsername(String username) this username = username; public String submitPersonInfo() (username); (email); ApplicationContext ac = FacesContextUtils getWebApplicationContext(FacesContext getCurrentInstance()); IExampleManager em = (IExampleManager) ac getBean( exampleService ); UserInfoVO uiVO = new UserInfoVO(); uiVO setUsername(username); uiVO setEmail(email); boolean flag = em setUserInfo(uiVO); if (flag) setResponse( 注册成功 ); return success ; else setResponse( 注册失败 ); return failure ; public void setResponse(String response) this response = response; public String getResponse() return null; public long getMaximum() return (this maximum); public void setMaximum(long maximum) this maximum = maximum; this maximumSet = true; public long getMinimum() return (this minimum); public void setMinimum(long minimum) this minimum = minimum; this minimumSet = true;
( )index jsp
<> <head> </head> <body> <jsp:forward page= /example/home jsp /> </body> </>
( )home jsp
<%@ page contentType= text/; charset=gbk %> <%@ taglib uri= prefix= h %> <%@ taglib uri= prefix= f %> <> <head> <title> 用户注册 </title> </head> <br> <f:view> <h:form id= helloForm > <table border= align= center bordercolor= # CC cellpadding= bordercolorlight= # > <tr> <td colspan= bgcolor= # CCFF >输入用户注册信息 </td> </tr> <tr> <td> <div align= right >用户名</div> </td> <td> <h:inputText id= username value= #InfoBean username > <f:validateLength minimum= #InfoBean minimum maximum= #InfoBean maximum /> </h:inputText> </td> </tr> <tr> <td> <div align= right >E_mail</div> </td> <td> <h:inputText id= email value= #InfoBean email /> </td> </tr> <tr> <td colspan= bgcolor= #FFFF > <span> <h:message id= message for= username /></span> </td> </tr> <tr> <td align= center colspan= > <h:mandButton id= submit action= #InfoBean submitPersonInfo value= 提交 /> </td> </tr> </table> </h:form> </f:view> </>
( )success jsp
<%@ page contentType= text/; charset=gbk %> <%@ taglib uri= prefix= h %> <%@ taglib uri= prefix= f %> <> <head> <title> 用户注册成功 </title> </head> <body bgcolor= white > <f:view> <h:form id= responseForm > <h:graphicImage id= successImg url= images/form success jpg alt= 注册成功! /> <h > <h:outputText id= result value= #InfoBean response /></h > <h:mandButton id= back value= 返回 action= su /> <p> </h:form> </f:view> </>
( )failure jsp
<%@ page contentType= text/; charset=gbk %> <%@ taglib uri= prefix= h %> <%@ taglib uri= prefix= f %> <> <head> <title> 用户注册失败 </title> </head> <body bgcolor= white > <f:view> <h:form id= responseForm > <h:graphicImage id= successImg url= images/form error jpg alt= 注册失败! /> <h > <h:outputText id= result value= #InfoBean response /></h > <h:mandButton id= back value= 返回 action= su /> <p> </h:form> </f:view> </>
( )web xml
<?xml version= ?> <web app xmlns= xmlns:xsi= instance xsi:schemaLocation= app_ _ xsd version= > <display name>example</display name> <context param> <param name>contextConfigLocation</param name> <param value>/WEB INF/applicationContext xml</param value> </context param> <listener> <listener class> sprntext ContextLoaderListener</listener class> </listener> <servlet> <display name>FacesServlet</display name> <servlet name>FacesServlet</servlet name> <servlet class>javax faces webapp FacesServlet</servlet class> <load on startup> </load on startup> </servlet> <servlet mapping> <servlet name>FacesServlet</servlet name> <url pattern>/example/*</url pattern> </servlet mapping> </web app>
( )applicationContext xml
<?xml version= encoding= UTF ?> <!DOCTYPE beans PUBLIC //SPRING//DTD BEAN//EN beans dtd > <beans> <bean id= dataSource class= springframework jndi JndiObjectFactoryBean > <property name= jndiName > <value>java:/MySqlDS</value> </property> </bean> <bean id= sessionFactory class= springframework orm hibernate LocalSessionFactoryBean > <property name= dataSource > <ref local= dataSource /> </property> <property name= mappingResources > <list> <value> /openv/spring/service/hibernate/UserInfo hbm xml </value> </list> </property> <property name= hibernateProperties > <props> <prop key= hibernate dialect > net sf hibernate dialect MySQLDialect </prop> <prop key= hibernate show_sql > true </prop> </props> </property> </bean> <bean id= transactionManager class= springframework orm hibernate HibernateTransactionManager > <property name= sessionFactory > <ref local= sessionFactory /> </property> </bean> <bean id= exampleServiceTarget class= openv spring service impl Example ManagerImpl > <property name= userinfo > <ref local= userinfoDAO /> </property> </bean> <bean id= exampleService class= springframework transaction interceptor TransactionProxyFactoryBean > <property name= transactionManager > <ref local= transactionManager /> </property> <property name= target > <ref local= exampleServiceTarget /> </property> <property name= transactionAttributes > <props> <prop key= get* > PROPAGATION_REQUIRED readOnly </prop> <prop key= set* > PROPAGATION_REQUIRED </prop> </props> </property> </bean> <bean id= userinfoDAO class= openv spring service dao impl UserInfoDAO > <property name= sessionFactory > <ref local= sessionFactory /> </property> </bean> </beans>
( )faces config xml
cha138/Article/program/Java/ky/201311/27861相关参考
知识大全 spring+hibernate+jbpm整合成功
终于搞定了在此感谢chenjin的指点 从日整合失败后这块就一直是我的心病我甚至都跑去了去发了一个帖这还是我第一次用英文问问题呢 最后的配置结果是 hibernatecfgxmljbpmcf
知识大全 Struts2 Spring Hibernate 的简单整合
Struts2SpringHibernate的简单整合 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧
JSF和Hibernate的比较 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! atbackin
实例讲解Spring集成JSF的最简单方式 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Spr
Spring整合Hessian 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Spring让He
Spring整合Struts 虽然Spring也提供了自己的MVC组件但一来Spring的MVC组件过于繁琐二 来Struts的拥护者实在太多因此很
知识大全 spring struts2 ibatis框架整合开发
这里主要介绍一下spring+struts+ibatis所需要的jar包文件spring所需包 以上包为spring配置基本包ibatis所需包 有解决方法的朋友们希望能回复 与struts整合
Struts整合spring方法(三) 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Sprin
知识大全 Spring系列第2部分:当Hibernate遇上Spring
Spring系列第2部分:当Hibernate遇上Spring 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来
Spring整合Quartz定时发送邮件 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 功能描述