- 浏览: 627460 次
- 性别:
- 来自: 杭州
-
文章分类
- 全部博客 (334)
- java core (12)
- struts2.x (2)
- spring (3)
- hibernate (8)
- jpa (6)
- maven (2)
- osgi (5)
- eclipse (4)
- struts2.x+spring2.x+hibernate 整合 (5)
- ebs (0)
- html (0)
- vaadin (1)
- css (0)
- jquery (0)
- javascript (0)
- svn (1)
- cvs (0)
- axas2.x (0)
- eclipse+maven (9)
- annotation (0)
- 基于OSGi的动态化系统搭建 (1)
- notenet (1)
- jboss eclipse (4)
- eclipse工具 (4)
- jdk1.6+maven3.0.3+nuxeo+svn+felix+cxf+spring+springDM (6)
- spring dm (1)
- Nexus介绍 (1)
- proxool listener (0)
- oracle (4)
- mysql (8)
- 搭建你的全文检索 (1)
- hibernatehibernatehibernate (0)
- cvsearchcvsearch (0)
- mycvseach (0)
- asdfasdfasdf (0)
- propertiey (0)
- hibernate annotation (0)
- libs (0)
- icam (2)
- start 数据库配置 (0)
- jboss (1)
- 让Eclipse启动时显示选择workspace的对话框 (1)
- table表头固定 (1)
- s2s3h4 (0)
- leaver (0)
- mycvsaerchddd (0)
- 关于jboss5.0.1部署 (4)
- bookmarks (0)
- PersistenceUnitDeployment (0)
- mycom (0)
- HKEY_CURRENT_USER = &H80000001 (0)
- syspath (1)
- css div (1)
- Dreamweaver CS5 (0)
- generate (0)
- mysql查看表结构命令 (1)
- LOG IN ERROR EMAIL TO SB (0)
- struts2 handle static resource (1)
- jsf (2)
- log4j (1)
- jbpm4.4 (2)
- down: jbpm4.4 (1)
- jstl1.2 (1)
- spring annotation (1)
- java design pattern (1)
- cache (1)
- ehcache (1)
- 11111 (0)
- myge (0)
- pom.xml (0)
- springquartz (0)
- OpenStack (9)
- hadoop (2)
- nginx (1)
- hadoop openstack (1)
- os (1)
- hadoop-2.6.0 zookeeper-3.4.6 hbase-0.98.9-hadoop2 集群 (5)
- hadoop2.7.0 ha Spark (2)
- tess (0)
- system (1)
- asdf (0)
- hbase (2)
- hbase create table error (1)
- ekl (1)
- gitignore (1)
- gitlab-ci.yml (1)
- shell (1)
- elasticsearch (2)
- Azkaban 3.0+ (1)
- centos用命令 (1)
- hive (1)
- kafka (1)
- CaptureBasic (0)
- CentOS7 (1)
- dev tools (1)
- README.md (1)
- Error (1)
- teamviewerd.service (1)
- scala (1)
- spark (1)
- standard (1)
- gitlab (1)
- IDEA (0)
- ApplicationContext (1)
- 传统数仓 (1)
- redis install (1)
- MYSQL AND COLUME (1)
- java版本选择 (1)
- hue (1)
- npm (1)
- es (1)
- 版本管理 (1)
- 升级npm版本 (1)
- git (1)
- 服务器参数设置 (1)
- 调大 IDEA 编译内存大小 (0)
- CentOS8安装GitLab (1)
- gitlab安装使用 (1)
最新评论
-
ssydxa219:
vim /etc/security/limits.confvi ...
ekl -
Gamehu520:
table中无数据
hbase 出现的问题 -
Xleer0102:
为什么都是只有问没有答,哭晕在厕所
hbase 出现的问题 -
jiajiao_5413:
itext table -
CoderDream:
不完整,缺com.tcs.org.demostic.pub.u ...
struts2.3.1.1+hibernate3.6.9Final+spring3.1.0+proxool+maven+annotation
P.S In this example, we are using MySQL database and deploy to Tomcat 6 web container.
1. Project Structure
Directory structure of this example Create a customer table and insert 2 dummy records.
2. Table Script
DROP
TABLE
IF
EXISTS
`developer.amdb`
.
`customer`
;
CREATE
TABLE
`developer.amdb`
.
`customer`
(
`CUSTOMER_ID`
bigint(
20
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,
`NAME`
varchar(
45
)
NOT
NULL
,
`ADDRESS`
varchar(
255
)
NOT
NULL
,
`CREATED_DATE`
datetime NOT
NULL
,
PRIMARY
KEY
(
`CUSTOMER_ID`
)
)
ENGINE=
InnoDB AUTO_INCREMENT
=
17
DEFAULT
CHARSET=
utf8;
INSERT
INTO
developer.amdb.
customer(
customer_id,
name,
address,
created_date)
VALUES
(
1
,
'developer.am1'
,
'address1'
,
now(
)
)
;
INSERT
INTO
developer.amdb.
customer(
customer_id,
name,
address,
created_date)
VALUES
(
2
,
'developer.am2'
,
'address2'
,
now(
)
)
;
3. Hibernate Stuff
A model class and Hibernate mapping file for customer table.
File : Customer.java
package com.developer.am.customer.model ; import java.util.Date ; public class Customer{ public long customerId; public String name; public String address; public Date createdDate; //getter and setter methods }
File : Customer.hbm.xml
<?xml version ="1.0" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name ="com.developer.am.customer.model.Customer" table ="customer" catalog ="developer.amdb" > <id name ="customerId" type ="long" > <column name ="CUSTOMER_ID" /> <generator class ="identity" /> </id> <property name ="name" type ="string" > <column name ="NAME" length ="45" not-null ="true" /> </property> <property name ="address" type ="string" > <column name ="ADDRESS" not-null ="true" /> </property> <property name ="createdDate" type ="timestamp" > <column name ="CREATED_DATE" length ="19" not-null ="true" /> </property> </class> </hibernate-mapping>
4. Spring Stuff
Spring’s BO and DAO classes for business logic and database interaction.
File : CustomerBo.java
package com.developer.am.customer.bo ; import java.util.List ; import com.developer.am.customer.model.Customer ; public interface CustomerBo{ void addCustomer( Customer customer) ; List< Customer> findAllCustomer( ) ; }
File : CustomerBoImpl.java
package com.developer.am.customer.bo.impl ; import java.util.List ; import com.developer.am.customer.bo.CustomerBo ; import com.developer.am.customer.dao.CustomerDao ; import com.developer.am.customer.model.Customer ; public class CustomerBoImpl implements CustomerBo{ CustomerDao customerDao; public void setCustomerDao( CustomerDao customerDao) { this .customerDao = customerDao; } public void addCustomer( Customer customer) { customerDao.addCustomer ( customer) ; } public List< Customer> findAllCustomer( ) { return customerDao.findAllCustomer ( ) ; } }
File : CustomerDao.java
package com.developer.am.customer.dao ; import java.util.List ; import com.developer.am.customer.model.Customer ; public interface CustomerDao{ void addCustomer( Customer customer) ; List< Customer> findAllCustomer( ) ; }
File : CustomerDaoImpl.java
package com.developer.am.customer.dao.impl ; import java.util.Date ; import java.util.List ; import com.developer.am.customer.dao.CustomerDao ; import com.developer.am.customer.model.Customer ; import org.springframework.orm.hibernate3.support.HibernateDaoSupport ; public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{ public void addCustomer( Customer customer) { customer.setCreatedDate ( new Date ( ) ) ; getHibernateTemplate( ) .save ( customer) ; } public List< Customer> findAllCustomer( ) { return getHibernateTemplate( ) .find ( "from Customer" ) ; } }
File : CustomerBean.xml
<?xml version ="1.0" encoding ="UTF-8" ?> <beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" > <bean id ="customerBo" class ="com.developer.am.customer.bo.impl.CustomerBoImpl" > <property name ="customerDao" ref ="customerDao" /> </bean> <bean id ="customerDao" class ="com.developer.am.customer.dao.impl.CustomerDaoImpl" > <property name ="sessionFactory" ref ="sessionFactory" /> </bean> </beans>
5. Spring + Database
Configure database detail in Spring.
File : db.properties
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/developer.amdb jdbc.username=root jdbc.password=password
File : DataSource.xml
<beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" > <bean class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name ="location" > <value> WEB-INF/classes/config/database/db.properties</value> </property> </bean> <bean id ="dataSource" class ="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name ="driverClassName" value ="${jdbc.driverClassName}" /> <property name ="url" value ="${jdbc.url}" /> <property name ="username" value ="${jdbc.username}" /> <property name ="password" value ="${jdbc.password}" /> </bean> </beans>
6. Spring + Hibernate
Integrate Hibernate and Spring via LocalSessionFactoryBean
.
File : HibernateSessionFactory.xml
<?xml version ="1.0" encoding ="UTF-8" ?> <beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" > <!-- Hibernate session factory --> <bean id ="sessionFactory" class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name ="dataSource" > <ref bean ="dataSource" /> </property> <property name ="hibernateProperties" > <props> <prop key ="hibernate.dialect" > org.hibernate.dialect.MySQLDialect</prop> <prop key ="hibernate.show_sql" > true</prop> </props> </property> <property name ="mappingResources" > <list> <value> com/developer.am/customer/hibernate/Customer.hbm.xml</value> </list> </property> </bean> </beans>
7. JSF 2.0
JSF managed bean to call Spring’s BO to add or get customer’s records from database.
File : CustomerBean.java
package com.developer.am ; import java.io.Serializable ; import java.util.List ; import com.developer.am.customer.bo.CustomerBo ; import com.developer.am.customer.model.Customer ; public class CustomerBean implements Serializable { //DI via Spring CustomerBo customerBo; public String name; public String address; //getter and setter methods public void setCustomerBo( CustomerBo customerBo) { this .customerBo = customerBo; } //get all customer data from database public List< Customer> getCustomerList( ) { return customerBo.findAllCustomer ( ) ; } //add a new customer data into database public String addCustomer( ) { Customer cust = new Customer( ) ; cust.setName ( getName( ) ) ; cust.setAddress ( getAddress( ) ) ; customerBo.addCustomer ( cust) ; clearForm( ) ; return "" ; } //clear form values private void clearForm( ) { setName( "" ) ; setAddress( "" ) ; } }
A JSF page to display existing customer records via h:dataTable
and a few text components to allow user to insert new customer record into database.
File : default.xhtml
<?xml version = "1.0" encoding= "UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns= "http://www.w3.org/1999/xhtml" xmlns:h= "http://java.sun.com/jsf/html" xmlns:f= "http://java.sun.com/jsf/core" > <h:head> <h:outputStylesheet library= "css" name = "table-style.css" / > </ h:head> <h:body> <h1 > JSF 2.0 + Spring + Hibernate Example</ h1 > <h:dataTable value = "#{customer.getCustomerList()}" var= "c" styleClass= "order-table" headerClass= "order-table-header" rowClasses= "order-table-odd-row,order-table-even-row" > <h:column> <f:facet name = "header" > Customer ID </ f:facet> #{c.customerId} </ h:column> <h:column> <f:facet name = "header" > Name </ f:facet> #{c.name} </ h:column> <h:column> <f:facet name = "header" > Address </ f:facet> #{c.address} </ h:column> <h:column> <f:facet name = "header" > Created Date </ f:facet> #{c.createdDate} </ h:column> </ h:dataTable> <h2 > Add New Customer</ h2 > <h:form> <h:panelGrid columns= "3" > Name : <h:inputText id = "name" value = "#{customer.name}" size = "20" required= "true" label = "Name" > </ h:inputText> <h:message for = "name" style = "color:red" / > Address : <h:inputTextarea id = "address" value = "#{customer.address}" cols = "30" rows = "10" required= "true" label = "Address" > </ h:inputTextarea> <h:message for = "address" style = "color:red" / > </ h:panelGrid> <h:commandButton value = "Submit" action = "#{customer.addCustomer()}" / > </ h:form> </ h:body> </ html >
8. JSF 2.0 + Spring
Integrate JSF 2.0 with Spring.
File : applicationContext.xml
<beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" > <!-- Database Configuration --> <import resource ="classes/config/spring/beans/DataSource.xml" /> <import resource ="classes/config/spring/beans/HibernateSessionFactory.xml" /> <!-- Beans Declaration --> <import resource ="classes/com/developer.am/customer/spring/CustomerBean.xml" /> </beans>
File : faces-config.xml
<?xml version ="1.0" encoding ="UTF-8" ?> <faces-config xmlns ="http://java.sun.com/xml/ns/javaee" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version ="2.0" > <application> <el-resolver> org.springframework.web.jsf.el.SpringBeanFacesELResolver </el-resolver> </application> <managed-bean> <managed-bean-name> customer</managed-bean-name> <managed-bean-class> com.developer.am.CustomerBean</managed-bean-class> <managed-bean-scope> session</managed-bean-scope> <managed-property> <property-name> customerBo</property-name> <value> #{customerBo}</value> </managed-property> </managed-bean> </faces-config>
File : web.xml
<?xml version ="1.0" encoding ="UTF-8" ?> <web-app xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns ="http://java.sun.com/xml/ns/javaee" xmlns:web ="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id ="WebApp_ID" version ="2.5" > <display-name> JavaServerFaces</display-name> <!-- Add Support for Spring --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <!-- Change to "Production" when you are ready to deploy --> <context-param> <param-name> javax.faces.PROJECT_STAGE</param-name> <param-value> Development</param-value> </context-param> <!-- Welcome page --> <welcome-file-list> <welcome-file> faces/default.xhtml</welcome-file> </welcome-file-list> <!-- JSF mapping --> <servlet> <servlet-name> Faces Servlet</servlet-name> <servlet-class> javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> 1</load-on-startup> </servlet> <!-- Map these files with JSF --> <servlet-mapping> <servlet-name> Faces Servlet</servlet-name> <url-pattern> /faces/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name> Faces Servlet</servlet-name> <url-pattern> *.jsf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name> Faces Servlet</servlet-name> <url-pattern> *.faces</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name> Faces Servlet</servlet-name> <url-pattern> *.xhtml</url-pattern> </servlet-mapping> </web-app>
9. Demo
Run it, fill in the customer data and click on the “submit” button.


相关推荐
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码.part1 其他部分详见我的上传列表,全部分卷下载完成才能解压。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun...
经典JAVA EE企业应用实战 基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发.part2
经典Java EE企业应用实战:基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发 part3
《经典Java EE企业应用实战:基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发》介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则包含Session Bean、Message Driven Bean的...
经典Java EE企业应用实战:基于WebLogic/JBoss的JSF+EJB 3+JPA整合开发 part2
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发 PDF 书籍 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则包含Session Bean、Message ...
[TipTec Development] JSF & Facelets & JBoss Seam 核心技术 (英文版) [TipTec Development] Essential JSF, Facelets & JBoss Seam (E-Book) ☆ 出版信息:☆ [作者信息] Kent Ka Iok Tong [出版机构] TipTec ...
经典JAVA EE企业应用实战 基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发。第二部分。
经典JAVA EE企业应用实战 基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发个人认为是不错的书
这篇名为“jboss selectManyCheckbox jsf扩展”的博文主要探讨了如何在JBoss环境中对这个组件进行自定义扩展,以满足特定的需求。在实际开发中,我们可能需要对默认的行为进行定制,比如改变渲染方式、增加验证规则...
[Apress] JSF 2 APIs & JBoss Seam 基础教程 (英文版) [Apress] Beginning JSF 2 APIs and JBoss Seam (E-Book) ☆ 出版信息:☆ [作者信息] Kent Ka Iok Tong [出版机构] Apress [出版日期] 2009年05月25日 ...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第9章 其他部分详见我的上传列表。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码.part2 其他部分详见我的上传列表,全部分卷下载完成才能解压。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第6章 其他部分详见我的上传列表。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第3章 其他部分详见我的上传列表 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则包含...
经典JAVA EE企业应用实战 基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发。第三部分。
### 关于《Beginning JSF2 APIs and JBoss Seam》的知识点总结 #### 一、书籍简介与背景 《Beginning JSF2 APIs and JBoss Seam》是一本深入介绍JavaServer Faces 2(简称JSF2)及其相关API以及JBoss Seam框架的...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码.part3 其他部分详见我的上传列表,全部分卷下载完成才能解压。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司...
经典JAVA EE企业应用实战基于WEBLOGIC JBOSS的JSF+EJB 3+JPA整合开发——源码第5章 其他部分详见我的上传列表。 本书介绍了Java EE规范的三大主要规范JSF、EJB 3和JPA,其中JSF是Sun公司提供的JSF RI;EJB 3部分则...