- 浏览: 106718 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zhaobin87:
...
Oracle 根据序列已有最大值自动生成累加序列 -
sc_1028:
mtain 写道 不错
谢谢支持
struts2、spring3、hibernate3整合 -
mtain:
不错
struts2、spring3、hibernate3整合 -
liufumingfeng:
...
修改ADT的默认路径 -
艾依然:
谢谢分享!
spring集成ibatis示例-websphere5.1选型webservice
最近公司要用struts2、spring3、hibernate3整合,自己弄了一套,网上有好多helloworld例子,我也记录下我的helloworld吧。
初了struts2,spring3,hibernate3包中的jar文件,还需要本人附件中的jar包进行引用,这些jar均来源各自官方网站下载。
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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-app_2_5.xsd"> <welcome-file-list> <welcome-file>searchAction</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
src/struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="com.scs.action" extends="struts-default"> <action name="TestAction" class="com.scs.action.TestAction"> <result name="success">/success.jsp</result> </action> <action name="regUserAction" class="com.scs.action.RegUserAction"> <result name="success">/success.jsp</result> <result name="failed">/regist.jsp</result> </action> <action name="searchAction" class="com.scs.action.SearchAction"> <result name="success">/search.jsp</result> </action> <action name="addAction" class="com.scs.action.AddAction"> <result name="success">/add.jsp</result> </action> </package> </struts>
src/struts.properties
struts.objectFactory = spring struts.objectFactory.spring.autoWire = name struts.i18n.encoding = utf-8 struts.multipart.maxSize=10000000 struts.devMode = true struts.enable.DynamicMethodInvocation = false
src/log4j.properties
log4j.rootLogger=WARN, Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=(%r ms) [%t] %-5p: %c#%M %x: %m%n log4j.logger.com.genuitec.eclipse.sqlexplorer=DEBUG log4j.logger.org.apache=INFO log4j.logger.org.hibernate=INFO
src/applicationContext.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 用注解方式注入bean --> <context:annotation-config /> <context:component-scan base-package="com.scs" /> <!-- 数据库连接池--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/TestSCS" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <!-- hibernate sessionFactory 创建 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>com/scs/pojo/TestUser.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 事物配置 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <bean id="regUserAction" class="com.scs.action.RegUserAction"> <property name="testUserDao" ref="testUserDao"></property> </bean> <bean id="searchAction" class="com.scs.action.SearchAction"> <property name="testUserDao" ref="testUserDao"></property> </bean> <bean id="testUserDao" class="com.scs.dao.impl.TestUserDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
com/scs/pojo/TestUser.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 package="com.scs.pojo"> <class name="TestUser" table="TEST_USER"> <id name="id" column="ID"> <generator class="identity"/> </id> <property name="name" type="java.lang.String" insert="true" column="NAME"></property> </class> </hibernate-mapping>
com.scs.pojo.TestUser
package com.scs.pojo; import java.io.Serializable; public class TestUser implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
com.scs.dao.TestUserDao
package com.scs.dao; import java.util.List; import com.scs.pojo.TestUser; public interface TestUserDao { // 创建用户 public Integer save(TestUser user); // 查询用户 public List<TestUser> search(); }
com.scs.dao.impl.TestUserDaoImpl
package com.scs.dao.impl; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.scs.dao.TestUserDao; import com.scs.pojo.TestUser; public class TestUserDaoImpl extends HibernateDaoSupport implements TestUserDao { @Override public Integer save(TestUser user) { return (Integer) getHibernateTemplate().save(user); } @SuppressWarnings("unchecked") @Override public List<TestUser> search() { return getHibernateTemplate().find("from TestUser"); } }
com.scs.action.AddAction
package com.scs.action; import com.opensymphony.xwork2.ActionSupport; public class AddAction extends ActionSupport{ private static final long serialVersionUID = 1L; @Override public String execute() throws Exception { return "success"; } }
com.scs.action.RegUserAction
package com.scs.action; import com.opensymphony.xwork2.ActionSupport; import com.scs.dao.TestUserDao; import com.scs.pojo.TestUser; public class RegUserAction extends ActionSupport { private static final long serialVersionUID = 1L; private TestUserDao testUserDao; private TestUser testUser; public TestUser getTestUser() { return testUser; } public void setTestUser(TestUser testUser) { this.testUser = testUser; } public TestUserDao getTestUserDao() { return testUserDao; } public void setTestUserDao(TestUserDao testUserDao) { this.testUserDao = testUserDao; } public String execute() { testUserDao.save(testUser); return "success"; } }
com.scs.action.SearchAction
package com.scs.action; import java.util.List; import com.opensymphony.xwork2.ActionSupport; import com.scs.dao.TestUserDao; import com.scs.pojo.TestUser; public class SearchAction extends ActionSupport { private static final long serialVersionUID = 1L; private TestUserDao testUserDao; private List<TestUser> users; public TestUserDao getTestUserDao() { return testUserDao; } public void setTestUserDao(TestUserDao testUserDao) { this.testUserDao = testUserDao; } public List<TestUser> getUsers() { return users; } public void setUsers(List<TestUser> users) { this.users = users; } public String execute() { users = testUserDao.search(); return "success"; } }
WebRoot/add.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="struts2,spring3,hibernate3"> <%@ taglib prefix="s" uri="/struts-tags"%> </head> <body> This is my JSP page. <br><br> <s:form action="regUserAction" method="get" name="testUser" > <table width="230" border="0" align="left" height="35"> <tbody> <tr> <td>姓名:</td> <td><input type="text" name="testUser.name" /></td></tr> <tr align="center"> <td colspan="2"><input type="submit" name="submit" value="提交" /><input type="reset" value="重置" /></td> </tr> </tbody></table> </s:form> </body> </html>
WebRoot/search.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="struts2,spring3,hibernate3"> </head> <body> <table width="230" border="1" align="left" height="35"> <tr align="center"> <td>ID</td> <td>姓名</td> </tr> <s:iterator value="users"> <tr> <td><s:property value="id" /></td> <td><s:property value="name" /></td> </tr> </s:iterator> </table> <dir> <s:a href="addAction" >增加</s:a> </dir> </body> </html>
- aopalliance-alpha1.jar (21.5 KB)
- 下载次数: 18
- commons-pool-1.5.6-bin.tar.gz (959.4 KB)
- 下载次数: 25
- slf4j-1.6.4.tar.gz (2.6 MB)
- 下载次数: 20
- commons-dbcp-1.4-bin.tar.gz (1.4 MB)
- 下载次数: 30
发表评论
-
Ehcache 使用
2012-01-05 19:51 0Ehcache是当前发展最快的java应用缓存处理工具,始于我 ... -
spring集成ibatis示例-websphere5.1选型webservice
2010-12-02 20:11 2298项目中需要新增一个子应用,用于webservice请求,由于公 ... -
dom4j实际应用
2008-06-10 14:31 1501创建Document基本操作 public static ... -
struts2 properties配置详解
2008-05-20 15:39 5651struts.properties文件,该文 ... -
Hibernate使用Projections进行聚合操作
2008-04-21 13:24 3110通过Hibernate进行字段中的数据计算,在JDBC中,就使 ... -
编写简单的XPath程序
2008-01-05 02:03 1565当前使用XPath 1.0 1,需求说明 假设要查询一个图书 ... -
JavaEE基础:JSP的9个内置对象
2007-12-11 23:50 21801,out: out对象是JspWriter类的实例,是向客 ...
相关推荐
Struts2 Spring3 Hibernate3 整合必须包(很完整)
Struts2 Spring3 Hibernate4 框架完美整合
Struts2 Spring3 Hibernate3.3框架整合,增删改查,包含有数据库建表语句,包含有JAR包,包含有源代码。包含有事务的配置以及运用。使用的是Oracle的序列来提供的主键自增,建表和建立序列的sql语句,已经放在工程...
struts+spring+hibernate整合
struts2 spring2 hibernate3整合源代码+jar包struts2 spring2 hibernate3整合源代码+jar包
本文并不想介绍Struts,Spring,Hibernate的原理系统架构等,本文地目的是通过一个较复杂地实例介绍如何整合Struts,Spring,Hibernate,网上现有的例子虽然也能达到目的,但功能都比较单一,复杂的例子时会有...
ssh三大框架的整合步骤,非常详细。包含spring整合struts、spring整合hibernate、声明式事务说明等。
12.6 整合Struts、Spring和Hibernate实现用户管理 12.6.1 Struts、Spring和Hibernate的整合方式 12.6.2 编写用户注册画面regedit.jsp 12.6.3 编写用户登录画面login.jsp 12.6.4 编写注册控制器RegeditAction.java ...
struts2 spring hibernate 整合
整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
使用mysql数据库的struts2 spring hibernate整合简单示例,也可参考我的:“struts2 spring hibernate整合要点、注意点”这篇文档来配置
S2SH整合 struts2 spring4 hibernate4
在weblogic下整合struts+spring+hibernate,实现struts portlet
struts,spring,hibernate三大框架的整合
Struts+Spring+Hibernate整合教程
平台是:MyElipse5.1,Tomcat5.59,Struts1.1,Spring1.2,Hibernate3.0,Sql server2000.
Struts2 Spring3 Hibernate4整合包,没有多余的jar.需要的请下载,我一直在用这个。
轻量级JavaEE企业应用实战_Struts2+Spring3+Hibernate整合开发_第3版.part5
现在的结构是,Struts负责显示层,Hibernate负责持久层,Spring负责中间的业务层,另外,由于Spring使用的依赖注射以及AOP(面向方面编程),所以它的这种内部模式非常优秀,以至于Spring自己也实现了一个使用依赖注射...
Struts2Spring4Hibernate4整合,Hibernate使用的是注解,没有使用Maven,这个是帮一个小伙伴整合做的demo