Struts2.3.4.1 + Spring3.1.2 + Hibernate4.1.6整合
2. web.xml配置
3. struts.xml配置
4. hibernate.cfg.xml配置
5. applicationContext.xml配置
6. log4j.properties配置
7. Dao层
8. Service层
9. Action层
1. Jar包
1) Struts 2.3.4.1
下载地址:http://struts.apache.org/download
- /lib/commons-fileupload-1.2.2.jar
- /lib/commons-io-2.0.1.jar
- /lib/commons-lang3-3.1.jar
- /lib/freemarker-2.3.19.jar
- /lib/javassist-3.11.0.GA.jar
- /lib/ognl-3.0.5.jar
- /lib/struts2-core-2.3.4.1.jar
- /lib/struts2-spring-plugin-2.3.4.1.jar
- /lib/xwork-core-2.3.4.1.jar
2) Spring 3.1.2
下载地址:http://www.springsource.org/download
- /dist/*
3) Hibernate 4.1.6
下载地址:http://sourceforge.net/projects/hibernate/files/hibernate4
- /lib/required/*
- /lib/envers/hibernate-envers-4.1.6.Final.jar
- /lib/jpa/hibernate-entitymanager-4.1.6.Final.jar
- /lib/optional/c3p0/c3p0-0.9.1.jar
- /lib/optional/c3p0/hibernate-c3p0-4.1.6.Final.jar
4) Aopalliance 1.0
下载地址:http://sourceforge.net/projects/aopalliance
- aopalliance.jar
5) Aspectj 1.7.0
下载地址:http://www.eclipse.org/aspectj/downloads.php
- aspectjrt.jar
- aspectjweaver.jar
6) Cglib 2.2.3
下载地址:http://sourceforge.net/projects/cglib/files
- cglib-2.2.3.jar
7) Asm 3.3
下载地址:http://forge.ow2.org/projects/asm
- asm-3.3.jar
8) Log4j 1.2.17
下载地址:http://logging.apache.org/log4j/1.2/download.html
- log4j-1.2.17.jar
9) MySQL Connector Java 5.1.21
下载地址:http://dev.mysql.com/downloads/connector/j
- mysql-connector-java-5.1.21-bin.jar
10)Commons Logging 1.1.1
下载地址:http://commons.apache.org/logging
- commons-logging-1.1.1.jar
2. web.xml配置
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app 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_3_0.xsd"
- version="3.0">
- <!-- Welcome File List -->
- <welcome-file-list>
- <welcome-file>login.html</welcome-file>
- </welcome-file-list>
- <!-- WebApp Root -->
- <context-param>
- <param-name>webAppRootKey</param-name>
- <param-value>webapp.root</param-value>
- </context-param>
- <!-- Spring Encoding Filter -->
- <filter>
- <filter-name>encodingFilter</filter-name>
- <filter-class>
- org.springframework.web.filter.CharacterEncodingFilter
- </filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- </filter>
- <!-- Spring Encoding Filter Mapping -->
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- Struts2 Filter -->
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.ng.filter.
- StrutsPrepareAndExecuteFilter
- </filter-class>
- </filter>
- <!-- Struts2 Filter Mapping -->
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!-- Log4j ConfigurationFile Location -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>classpath:log4j.properties</param-value>
- </context-param>
- <!-- Spring Log4j Listener -->
- <listener>
- <listener-class>
- org.springframework.web.util.Log4jConfigListener
- </listener-class>
- </listener>
- <!-- Spring ConfigurationFile Location -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <!-- Spring Context Listener -->
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- </listener-class>
- </listener>
- <!-- Spring Web Request Listener -->
- <listener>
- <listener-class>
- org.springframework.web.context.request.RequestContextListener
- </listener-class>
- </listener>
- <!-- Spring Introspector Cleanup Listener -->
- <listener>
- <listener-class>
- org.springframework.web.util.IntrospectorCleanupListener
- </listener-class>
- </listener>
- </web-app>
3. struts.xml配置
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <struts>
- <constant name="struts.devMode" value="false" />
- <constant name="struts.i18n.encoding" value="UTF-8" />
- <package name="default" namespace="/" extends="struts-default">
- <action name="login" method="login" class="loginAction">
- <result name="input">/login.html</result>
- <result name="success">/home.jsp</result>
- </action>
- </package>
- </struts>
4. hibernate.cfg.xml配置
- <?xml version='1.0' encoding='UTF-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="dialect">
- org.hibernate.dialect.MySQLDialect
- </property>
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <property name="hbm2ddl.auto">update</property>
- <mapping class="com.txazo.domain.User" />
- </session-factory>
- </hibernate-configuration>
5. 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:p="http://www.springframework.org/schema/p"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/
- spring-context-3.1.xsd">
- <!-- DataSource -->
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
- destroy-method="close">
- <property name="driverClass" value="com.mysql.jdbc.Driver" />
- <property name="jdbcUrl"
- value="jdbc:mysql://127.0.0.1:3306/txazo" />
- <property name="user" value="root" />
- <property name="password" value="root" />
- </bean>
- <!-- SessionFactory -->
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
- p:dataSource-ref="dataSource"
- p:configLocation="classpath:hibernate.cfg.xml" />
- <!-- TransactionManager -->
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate4.HibernateTransactionManager"
- p:sessionFactory-ref="sessionFactory" />
- <!-- Spring Advice -->
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="get*" read-only="true"></tx:method>
- <tx:method name="*"></tx:method>
- </tx:attributes>
- </tx:advice>
- <!-- Spring Aop Config -->
- <aop:config>
- <aop:pointcut id="pointcut"
- expression="
- execution(* com.txazo.service.impl.*Impl.*(..))" />
- <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
- </aop:config>
- <!-- Dao -->
- <bean id="baseDao" class="com.txazo.dao.impl.BaseDaoImpl">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- </property>
- </bean>
- <!-- Service -->
- <bean id="userService" class="com.txazo.service.impl.UserServiceImpl">
- <property name="baseDao">
- <ref bean="baseDao" />
- </property>
- </bean>
- <!-- Action -->
- <bean id="loginAction" class="com.txazo.action.LoginAction"
- scope="session">
- <property name="userService">
- <ref bean="userService" />
- </property>
- </bean>
- </beans>
6. log4j.properties配置
- # Set The RootLogger
- log4j.rootLogger=warn, console
- # Direct Log Messages To Console
- log4j.appender.console=org.apache.log4j.ConsoleAppender
- log4j.appender.console.Target=System.out
- log4j.appender.console.layout=org.apache.log4j.PatternLayout
- log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c:%L - %m%n
- # Log Hibernate
- log4j.logger.org.hibernate=error
- # Log Just The SQL
- log4j.logger.org.hibernate.SQL=debug
- # Log Schema Export Update
- log4j.logger.org.hibernate.tool.hbm2ddl=debug
7. Dao层
- public interface BaseDao {
- public <T> void save(T t);
- public <T> void delete(T t);
- public <T> void delete(Class<T> entityClass, Integer id);
- public <T> void update(T t);
- public <T> T get(Class<T> entityClass, Integer id);
- public <T> List<T> findAll(String hql, Class<T> entityClass);
- public <T> List<T> findAll(String hql, Class<T> entityClass,
- Object param);
- public <T> List<T> findAll(String hql, Class<T> entityClass,
- Object[] params);
- public <T> List<T> findByPage(final String hql, final Class<T>
- entityClass, final int firstResult, final int maxResult);
- public <T> List<T> findByPage(final String hql, final Class<T>
- entityClass, final Object param, final int firstResult,
- final int maxResult);
- public <T> List<T> findByPage(final String hql, final Class<T>
- entityClass, final Object[] params,
- final int firstResult, final int maxResult);
- }
- public class BaseDaoImpl implements BaseDao {
- private SessionFactory sessionFactory;
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
- public Session getSession() {
- return sessionFactory.getCurrentSession();
- }
- @Override
- public <T> void save(T t) {
- getSession().save(t);
- }
- @Override
- public <T> void delete(T t) {
- getSession().delete(t);
- }
- @Override
- public <T> void delete(Class<T> entityClass, Integer id) {
- getSession().delete(get(entityClass, id));
- }
- @Override
- public <T> void update(T t) {
- getSession().update(t);
- }
- @Override
- public <T> T get(Class<T> entityClass, Integer id) {
- return (T) getSession().get(entityClass, id);
- }
- @Override
- public <T> List<T> findAll(String hql, Class<T> entityClass) {
- return findAll(hql, entityClass, new Object[] {});
- }
- @Override
- public <T> List<T> findAll(String hql, Class<T> entityClass, Object param) {
- return findAll(hql, entityClass, new Object[] { param });
- }
- @Override
- public <T> List<T> findAll(String hql, Class<T> entityClass,
- Object[] params) {
- Query query = getSession().createQuery(hql);
- for (int i = 0; i < params.length; i++) {
- query.setParameter(i, params[i]);
- }
- return (List<T>) query.list();
- }
- @Override
- public <T> List<T> findByPage(final String hql, Class<T> entityClass,
- final int firstResult, final int maxResult) {
- return findByPage(hql, entityClass, new Object[] {}, firstResult,
- maxResult);
- }
- @Override
- public <T> List<T> findByPage(final String hql, Class<T> entityClass,
- final Object param, final int firstResult, final int maxResult) {
- return findByPage(hql, entityClass, new Object[] { param },
- firstResult, maxResult);
- }
- @Override
- public <T> List<T> findByPage(final String hql, Class<T>
- entityClass, final Object[] params, final int firstResult,
- final int maxResult) {
- Query query = getSession().createQuery(hql);
- for (int i = 0; i < params.length; i++) {
- query.setParameter(i, params[i]);
- }
- query.setFirstResult(firstResult);
- query.setMaxResults(maxResult);
- return (List<T>) query.list();
- }
- }
8. Service层
- public interface UserService {
- public User login(User user);
- }
- public class UserServiceImpl implements UserService {
- private BaseDao baseDao;
- public void setBaseDao(BaseDao baseDao) {
- this.baseDao = baseDao;
- }
- @Override
- public User login(User user) {
- List<User> list = baseDao.findAll(
- "from User where username = ? and password = ?", User.class,
- new Object[] { user.getUsername(), user.getPassword() });
- if (list.size() == 1) {
- return list.get(0);
- }
- return null;
- }
- }
9. Action层
- public class ActionBase extends ActionSupport implements RequestAware,
- SessionAware, ApplicationAware {
- private static final long serialVersionUID = 1L;
- protected Map<String, Object> request;
- protected Map<String, Object> session;
- protected Map<String, Object> application;
- public Map<String, Object> getRequest() {
- return request;
- }
- public Map<String, Object> getSession() {
- return session;
- }
- public Map<String, Object> getApplication() {
- return application;
- }
- @Override
- public void setRequest(Map<String, Object> request) {
- this.request = request;
- }
- @Override
- public void setSession(Map<String, Object> session) {
- this.session = session;
- }
- @Override
- public void setApplication(Map<String, Object> application) {
- this.application = application;
- }
- }
- public class LoginAction extends ActionBase {
- private static final long serialVersionUID = 1L;
- private String username;
- private String password;
- private UserService userService;
- public void setUserService(UserService userService) {
- this.userService = userService;
- }
- public String login() throws Exception {
- User user = new User(username, password);
- User login = userService.login(user);
- if (login != null) {
- session.put("user", login);
- return SUCCESS;
- }
- return INPUT;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
相关Jar包下载如下:
- aopalliance-1.0.zip (2.9 KB)
- 下载次数: 408
- struts-2.3.4.1.zip (3.2 MB)
- 下载次数: 354
- cglib-2.2.3.zip (246.5 KB)
- 下载次数: 354
- asm-3.3.zip (40.6 KB)
- 下载次数: 328
- aspectj-1.7.0.zip (1.7 MB)
- 下载次数: 415
- hibernate-4.1.6.zip (6.6 MB)
- 下载次数: 393
- log4j-1.2.17.zip (432.4 KB)
- 下载次数: 314
- spring-framework-3.1.2.zip (4.6 MB)
- 下载次数: 409
- mysql-connector-java-5.1.21.zip (773 KB)
- 下载次数: 289
- commons-logging-1.1.1.zip (55.1 KB)
- 下载次数: 297
Struts2.3.4.1 + Spring3.1.2 + Hibernate4.1.6整合的更多相关文章
- Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合
java教程|Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合教程并测试成功一.创建项目二.搭建struts-2.3.4.11.struts2必须的Jar包(放到W ...
- 基于Struts2.3.x+Spring3.2.x+Hibernate4.2.x+EasyUI1.3.4+Maven架构的示例程序
基于Struts2.3.x+Spring3.2.x+Hibernate4.2.x+EasyUI1.3.4+Maven架构的示例程序 不知道为什么,保存的时候显示有一个连接为违禁内容,可能是…………. ...
- SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
下载地址: http://pan.baidu.com/s/1qWDinyk 一 开发环境 1.动态web工程 2.部分依赖 hibernate-release-4.1.0.Final.zip hibe ...
- Struts2+Hibernate4+Spring4框架整合搭建Java项目原型
收藏 http://www.cnblogs.com/mageguoshi/p/5850956.html Struts2+Hibernate4+Spring4框架整合搭建Java项目原型
- springmvc+spring3+hibernate4框架简单整合,简单实现增删改查功能
转自:https://blog.csdn.net/thinkingcao/article/details/52472252 C 所用到的jar包 数据库表 数据库表就不用教大家了,一张表,很简 ...
- Spring3系列4-多个配置文件的整合
Spring3系列4-多个配置文件的整合 在大型的Spring3项目中,所有的Bean配置在一个配置文件中不易管理,也不利于团队开发,通常在开发过程中,我们会按照功能模块的不同,或者开发人员的不同,将 ...
- SSH:Struts2.2+Hibernate3.6+Spring3.1分页示例[转]
参考资料 1 ssh分页(多个例子) http://useryouyou.iteye.com/blog/593954 2 ssh2分页例子 http://459104018-qq-com.iteye. ...
- JSP和Struts2、Hibernate、Spring3基础内容和原理
一.JSP工作原理 1.首先是利用客户端浏览器,然后由客户端浏览器请求JSP页面,向JSP服务器发出请求. 2.JSP服务器内部原理 JSP服务器首先在收到客户端传送过来的请求后,将JSP页面编译成S ...
- Spring3.1.2与Hibernate4.1.8整合
整合Spring3.1.2 与 Hibernate 4.1.8 首先准备整合jar: Spring3.1.2: org.springframework.aop-3.1.2.RELEASE.jar or ...
随机推荐
- ASP.NET Core中使用默认MVC路由
ASP.NET Core里Route这块的改动不大,只是一些用法上有了调整,提供了一些更加简洁的语法. 而对于自定义路由的支持当然也是没有问题的,这个功能应该是从MVC1.0版本就已经有这个功能. 先 ...
- jsp继承rapid库
如果jsp不使用继承方式开发,而是用标准的指令或动作元素去include,实在是太多重复代码. rapid-framework是谷歌的一个项目,可以实现jsp网页的继承,也就是书写模板页. 但是在ma ...
- 开启停止wifi热点bat脚本
@echo offcolor 2title 启停无线WIFI echo 启动WIFI=======>按1键 echo ...
- Asp.NET MVC4 + Ajax 实现多文件上传
本文转自http://www.cnblogs.com/freeliver54/archive/2013/05/15/3079700.html JS部分测试可以,jQuery部分没有测试先留着 HTML ...
- C# Windows服务创建应用
创建项目 1.创建windows服务项目 2.右键点击Service1.cs,查看代码, 用于编写操作逻辑代码 3.OnStart函数在启动服务时执行,OnStop函数在停止服务时执行.代码中OnSt ...
- Linux下剪切拷贝命令
Linux下剪切拷贝命令 命令格式: mv source dest mv: 命令字 source: 源文件 dest: 目的地址 Linux下拷贝命令 命令格式:cp ...
- 基于easyUI实现权限管理系统(三)——角色管理
此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 相关文件介绍 1. role.jsp:角色管理界面 <!DOCTYPE html PUBLIC "-//W3 ...
- lintcode 题目记录2
判断字符串是否是互为置换,类似 替换字符串之类的遍历就行了.. class Solution: # @param {string} A a string # @param {string} B a s ...
- cf1043F. Make It One(dp 容斥原理)
题意 题目链接 给出\(n\)个数,问最少选几个数,使他们的\(gcd = 1\) Sol 好神仙啊qwq. 首先,如果答案存在,那么最多为\(7\)(因为前\(7\)个质数乘起来\(>= 3e ...
- 记录开发Nodejs c++ addon的一些经验(四、electron)
如果我们要在electron里使用我们开发的addon,那么直接使用是不行的. 官方的解释是:Electron 同样也支持原生模块,但由于和官方的 Node 相比使用了不同的 V8 引擎,如果你想编译 ...