搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台

View Code

package com.ims.web.controller;
import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.ModelAttribute;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class BaseController {
    /**
     *  AJAX访问返回操作成功状态标识符
     */
    protected static final String STATUS_SUCCESS = "success";
    /**
     *  AJAX访问返回操作失败状态标识符
     */
    protected static final String STATUS_ERROR = "error";

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;

    /**
     * 每个controller方法执行前被执行
     */
    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request,
            HttpServletResponse response) {
        this.request = request;
        this.response = response;
        this.session = request.getSession();
    }

    /**
     * 取得session中的值
     * @param name session主键
     * @return 主键对应的值
     */
    public Object getSession(String name) {
        return session.getAttribute(name);
    }

    /**
     * 往session中添加键值对
     * @param name session主键
     * @param obj session值
     */
    public void setSession(String name, Object obj) {
        session.setAttribute(name, obj);
    }

    /**
     * 添加cookie
     * @param key cookie主键
     * @param value cookie值
     */
    public void addCookie(String key, String value){
        Cookie cookie = new Cookie(key, value);
        cookie.setPath("/");// 这个要设置  
        cookie.setMaxAge(60*60*24*30);//保留一个月 以秒为单位  
        response.addCookie(cookie);
    }

    /**
     * 删除cookie
     * @param key cookie主键
     */
    public void deleteCookie(String key){
        Cookie cookies[] = request.getCookies();  
        if (cookies != null) {  
            for (int i = 0; i < cookies.length; i++) {  
                if (cookies[i].getName().equals(key)) {  
                    Cookie cookie = new Cookie(key,null);
                    cookie.setPath("/");//设置成跟写入cookies一样的  
                    cookie.setMaxAge(0);  
                    response.addCookie(cookie);  
                }  
            }  
        }  
    }

    /**
     * 取得cookie的值
     * @param key cookie主键
     */
    public String getCookieValue(String key) {
        String cookieVal = null;
        for(Cookie cookie : request.getCookies()){
            if (cookie.getName().equals(key)) {   
                try {
                    cookieVal = URLDecoder.decode(cookie.getValue(), "UTF-8");
                } catch (Exception e) {} 
                break;
            }  
        }
        return cookieVal;
    }

    /**
     * 取得访问项目的url
     */
    public String getBaseUrl(){
        return request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath() ;
    }

    /**
     * ajax输出
     * @param content 输出的文本内容
     * @param type 输出的文本类内容
     */
    public void ajax(String content, String type) {
        try {
            response.setContentType(type + ";charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            response.getWriter().write(content);
            response.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 响应json格式的字符串
     * @param content json格式的字符串
     */
    public void ajax(String content) {
        ajax(content, "application/json");
    }

    /**
     * 响应带状态的json格式的数据
     * @param status
     * @param content
     */
    public void ajaxJson(String status, Object content){
        String json = "{\"status\" : \""+status+"\", " +
                "\"message\" : "+JSON.toJSONString(content)+" }";
        ajax(json, "application/json");
    }

    /**
     * 响应json格式的数据
     * @param content
     */
    public void ajaxJson(Object content) {    
        String json = JSON.toJSONString(content, SerializerFeature.WriteDateUseDateFormat);
        ajax(json, "application/json");
    }

}

  4. hibernate.cfg.xml

spring-aop-4.3.4.RELEASE.jar
spring-beans-4.3.4.RELEASE.jar
spring-context-4.3.4.RELEASE.jar
spring-core-4.3.4.RELEASE.jar
spring-expression-4.3.4.RELEASE.jar
spring-jdbc-4.3.4.RELEASE.jar
spring-orm-4.3.4.RELEASE.jar
spring-tx-4.3.4.RELEASE.jar
spring-web-4.3.4.RELEASE.jar
spring-webmvc-4.3.4.RELEASE.jar

  3. controllerServlet.xml

View Code

图片 1图片 2

    2. 点击此翻开并下载要求的
MySQL Server 数据库,推荐接纳30个人

  2. applicationContextXxx.xml

  2. 基础dao类

package com.ims.persistence.base;

import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.jdbc.Work;

public class BaseDaoImpl<T extends Serializable> implements BaseDao<T>{          

    private SessionFactory sessionFactory;

    public BaseDaoImpl(){
        super();
    }


    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }


    /**
     * 返回数据库session对象
     * @return
     */
    protected Session getSession(){
        return sessionFactory.getCurrentSession();
    }

    /**
     * 保存实体对象
     * @param entity 实体对象
     */
    @Override
    public void save(T entity){
        Session session = getSession();
        session.save(entity);        
        session.flush();
        session.evict(entity);
    }

    /**
     * 更新实体对象
     * @param 实体对象
     */
    @Override
    public void update(T entity){
        Session session = getSession();
        session.update(entity);        
        session.flush();
        session.evict(entity);
    }

    /**
     * 保存或更新实体对象
     * @param entity 实体对象
     */
    @Override
    public void saveOrUpdate(T entity) {        
        Session session = getSession();
        session.saveOrUpdate(entity);        
        session.flush();
        session.evict(entity);    
    }

    /**
     * 删除实体对象
     * @param entity 实体对象
     */
    @Override
    public void delete(T entity){
        Session session = getSession();
        session.delete(entity);        
        session.flush();
        session.evict(entity);
    }    

    /**
     * 查询hql语句,返回唯一结果
     * @param hql 
     */
    @Override
    public Object findUniqueResult(String hql){
        Query query = getSession().createQuery(hql);
        return query.uniqueResult();
    }

    /**
     * 执行sql语句,更新数据库
     * @param sql
     */
    @Override
    public void updateBySql(final String sql){
        getSession().doWork(new Work() {   
            @Override
            public void execute(Connection connection) throws SQLException {
                connection.prepareStatement(sql).executeUpdate();
            }
        });
    }    

    /**
     * 通过Criteria对象查询,返回实体对象结果集
     * @param detachedCriteria 离线的Criteria对象
     * @return 实体对象结果集
     */
    @Override
    public List findByCriteria(DetachedCriteria detachedCriteria){
        Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());
        List records = criteria.list();
        return records;
    }

    /**
     * 通过sql语句查询,返回map对象结果集
     * @param sql 
     * @return map对象结果集
     */
    @Override
    public List<Map<String, Object>> findBySql(final String sql){
        final List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        getSession().doWork(new Work() {   
            @Override
            public void execute(Connection connection) throws SQLException {
                ResultSet rs = connection.prepareStatement(sql).executeQuery();
                result.addAll(RsHelper.rSToList(rs));
            }
        });
        return result;
    }

    /**
     * 查询sql语句,返回唯一结果
     * @param sql 
     */
    @Override
    public Object findUniqueResultBySql(String sql) {    
        return getSession().createSQLQuery(sql.toString()).uniqueResult();
    }

    /**
     * 通过Criteria对象查询,返回结果集的记录数
     * @param detachedCriteria 离线的Criteria对象
     * @return 结果集的记录数
     */
    @Override
    public long getCount(DetachedCriteria detachedCriteria) {
        Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());
        Object object = criteria.setProjection(Projections.rowCount()).uniqueResult();
        criteria.setProjection(null);
        Long totalRow = Long.valueOf(String.valueOf(object));
        return totalRow;
    }

    /**
     * 通过Criteria对象进行分页查询,返回实体对象结果集
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @param detachedCriteria 离线的Criteria对象
     * @return 实体对象结果集 
     */
    @Override
    public List<T> findPage(int pageNum, int pageSize, 
            DetachedCriteria detachedCriteria){
        Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());
        List<T> records = criteria.setFirstResult((pageNum-1) * pageSize).setMaxResults(pageSize).list();
        return records;
    }

    /**
     * 通过sql语句,进行分页查询,返回分页对象
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @param sql
     * @return 分页对象
     */
    @Override
    public Pagination findPage(final int pageNum, final int pageSize,final String sql){
        final Pagination page = new Pagination();
        getSession().doWork(new Work() {   
            @Override
            public void execute(Connection connection) throws SQLException {
                String countSql = MessageFormat.format("select count(*) from ({0}) page", sql);
                ResultSet rs = connection.prepareStatement(countSql).executeQuery();
                page.setTotal(Long.valueOf(RsHelper.getUniqueResult(rs).toString()));

                long firstResult = (pageNum - 1)*pageSize;
                String selectSql = MessageFormat.format("select * from ({0}) page limit {1},{2}", sql, firstResult, firstResult+pageSize);
                page.setRows(RsHelper.rSToList(connection.prepareStatement(selectSql).executeQuery()));
            }
        });

        return

    1.2. XxxBaseController.java,子项指标功底controller类:

  2. aspectjweaver-1.8.9.jar,spring AOP 正视 aspectj
来促成的,可点击此下载 

二. 工程搭建

图片 3

View Code

View
Code

View Code

图片 4图片 5

图片 6图片 7

五. 配置文件介绍

    子项目 mms 全称:material
management system,材质量管理理种类

  5. log4j-1.2.17.jar,帮忙 java 1.陆 、spring-4.3.4
的万丈稳定版本,可点击此下载  

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd 
        http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.4">
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>

  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
            classpath:applicationContext.xml,
            classpath:applicationContextXxx.xml
    </param-value>
  </context-param>

  <listener>   
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>   
  </listener>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

  <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>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:controllerServlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

图片 8图片 9

图片 10图片 11

    功用:设置请求、响应对象;session、cookie操作;ajax访问归来json数据;

  2. 将下载的工程文件按目录复制到 ims 工程中

 

  4. 点击此找到并下载
 apache-tomcat-6.0.48.zip,兼容叁九个人和陆十六位版本

  

  1. Eclipse –> File –> New –> Dynamic Web Project –>
输入工程名 ims –> Next –>

  5. log4j.properties

一. 成本环境

  4. slf4j-1.7.21,spring 的日志记录选用:jc-over-slf4j —> slf4j
—> log4j,可点击此下载获得:

  1. 点击此查看并下载需求的 Eclipse
IDE for Java EE Developers 开发工具,推荐选拔三十人

View Code

jackson-annotations-2.3.0.jar
jackson-core-2.3.0.jar
jackson-databind-2.3.0.jar
src
 |--com
 |   |--ims
 |   |   |--common
 |   |   |--persistence
 |   |   |       |--base
 |   |   |       |--dao
 |   |   |       |   |--xxx
 |   |   |       |       |--impl
 |   |   |       |--model
 |   |   |            |--xxx
 |   |   |--service
 |   |   |     |--xxx
 |   |   |         |--impl
 |   |   |--web
 |   |   |   |--controller
 |   |   |   |      |---xxx


WebContent
    |--common
    |--content
    |     |--css
    |     |--images
    |     |--js
    |--sql
    |   |--xxx
    |--view
    |   |--xxx
    |--viewModel
    |      |--xxx

 

图片 12图片 13

图片 14图片 15

View Code

<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">  
    <context:component-scan base-package="com" use-default-filters="false">
        <context:include-filter type="aspectj" expression="com.ims.persistence.dao..*.impl.*DaoImpl"/>
        <context:include-filter type="aspectj" expression="com.ims.service..*.impl.*BSImpl"/>
    </context:component-scan>   

    <!-- log4jdbc,需要依赖slf4j框架,拦截输出完整sql语句 -->
    <bean id="log4jdbcInterceptor" class="net.sf.log4jdbc.DataSourceSpyInterceptor" />
    <bean id="dataSourceLog4jdbcAutoProxyCreator"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="interceptorNames">
            <list>
                <value>log4jdbcInterceptor</value>
            </list>
        </property>
        <property name="beanNames">
            <list>                
                <value>xxxDatasource</value>
            </list>
        </property>
    </bean>
</beans>

    子项目 iot 全称:Internet of
things,物联网系统

图片 16图片 17

package com.ims.web.controller.xxx;

import com.ims.web.controller.BaseController;

public class XxxBaseController extends BaseController{

}

图片 18图片 19

图片 20图片 21

View Code

  7. hibernate-release-4.2.21.Final,帮忙 java 1.6
的最高版本,可点击此下载并在
libs/required 文件夹下得到:

图片 22

    功能:数据库的保存、更新、删除;sql、hql查询;分页查询;调用存款和储蓄进度

图片 23图片 24

package com.ims.persistence.base;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;

/**
 * 统一数据访问接口
 */
public interface BaseDao<T extends Serializable> {

    /**
     * 保存实体对象
     * @param entity 实体对象
     */
    public void save(T entity); 

    /**
     * 更新实体对象
     * @param 实体对象
     */
    public void update(T entity);

    /**
     * 保存或更新实体对象
     * @param entity 实体对象
     */
    public void saveOrUpdate(T entity);

    /**
     * 删除实体对象
     * @param entity 实体对象
     */
    public void delete(T entity);

    /**
     * 查询hql语句,返回唯一结果
     * @param hql 
     */
    public Object findUniqueResult(String hql); 

    /**
     * 执行sql语句,更新数据库
     * @param sql
     */
    public void updateBySql(String sql);

    /**
     * 通过Criteria对象查询,返回实体对象结果集
     * @param detachedCriteria 离线的Criteria对象
     * @return 实体对象结果集
     */
    public List findByCriteria(DetachedCriteria detachedCriteria);

    /**
     * 通过sql语句查询,返回map对象结果集
     * @param sql 
     * @return map对象结果集
     */
    public List<Map<String, Object>> findBySql(String sql);

    /**
     * 查询sql语句,返回唯一结果
     * @param sql 
     */
    public Object findUniqueResultBySql(String sql);

    /**
     * 通过Criteria对象查询,返回结果集的记录数
     * @param detachedCriteria 离线的Criteria对象
     * @return 结果集的记录数
     */
    public long getCount(DetachedCriteria detachedCriteria);

    /**
     * 通过Criteria对象进行分页查询,返回实体对象结果集
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @param detachedCriteria 离线的Criteria对象
     * @return 实体对象结果集 
     */
    public List<T> findPage(int pageNum, int pageSize, DetachedCriteria detachedCriteria);

    /**
     * 通过sql语句,进行分页查询,返回分页对象
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @param sql
     * @return 分页对象
     */
    public Pagination findPage(int pageNum, int pageSize, String sql); // 查找分页对象列表

    /**
     * 调用存储过程,返回单结果集
     * @param proceName 存储过程名称
     * @param params 输入参数集合
     * @return map对象结果集
     */
    public List<Map<String, Object>> callProcedure(String proceName, final List<Object> params);
}

    修改 Default output folder 为:WebContent/WEB-INF/classes –>
Finish

#输出级别和输出位置 ; 包中只有级别大于或等于配置级别,才允许输出
log4j.rootLogger=WARN,console,roll

#控制台输出
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n

#按日期滚动输出
log4j.appender.roll=org.apache.log4j.DailyRollingFileAppender
log4j.appender.roll.File=${catalina.base}/logs/ims/ims.log
log4j.appender.roll.layout=org.apache.log4j.PatternLayout
log4j.appender.roll.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS}    %p    %t    %c    %m%n

#继承rootLogger的输出位置
log4j.logger.com.ims = WARN
log4j.logger.org.hibernate.cache = ERROR
log4j.logger.org.directwebremoting = ERROR
#显示sql语句的参数
#log4j.logger.org.hibernate.type=trace 

log4j.logger.jdbc.connection=OFF
log4j.logger.jdbc.audit=OFF
log4j.logger.jdbc.resultset=OFF
log4j.logger.jdbc.sqlonly=OFF
#INFO、OFF
log4j.logger.jdbc.sqltiming=INFO

  5. 点击此下载
ims 工程文件

    子项目 sys
全称:system,基础新闻、权限管理体系

  注:以下的xxx均代表子项目名称,如:

View Code

View Code

      BaseDao.java

图片 25图片 26

  6. log4jdbc4-1.2.1.jar,jdbc层日志框架,可点击此下载

  9. fastjson-1.2.21.jar

  1. spring-framework-4.3.4.RELEASE,可点击此下载并在
libs 文件夹下获得: 

View Code

  1. 基础controller类

三. 工程目录结构介绍

 

  1. applicationContext.xml

  3. jackson-2.3.0,,帮衬 spring-4.3.4 的最低版本,可点击此下载

<?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="hibernate.order_updates">true</property>        
        <property name="hibernate.show_sql">false</property>
        <!-- none -->
        <property name="hibernate.hbm2ddl.auto">update</property>        

        <property name="hibernate.c3p0.max_size">30</property>   
         <property name="hibernate.c3p0.min_size">5</property>    
         <property name="hibernate.c3p0.timeout">3000</property>
         <property name="hibernate.c3p0.max_statements">50</property>         
        <!--每隔多少秒检测连接是否可正常使用  -->    
        <property name="c3p0.idle_test_period">121</property>  
        <!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3-->    
        <property name="c3p0.acquire_increment">1</property>  
        <property name="c3p0.validate">true</property>

        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
    </session-factory>

</hibernate-configuration>

  

 

六. 类文件介绍

View Code

四. jar包介绍

<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

    <bean id="xxxDatasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">        
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />        
        <property name="url" value="jdbc:mysql://localhost:3306/xxx?characterEncoding=utf8" />        
        <property name="username" value="root" />        
        <property name="password" value="123456" />    
    </bean>

    <bean id="xxxSessionFactory" 
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">    
          <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
        <property name="dataSource" ref="xxxDatasource" />                                                    
        <property name="packagesToScan">
            <list>
                <value>com.ims.persistence.model.xxx</value>
            </list>    
        </property>        
    </bean>

    <bean id="xxxTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="xxxSessionFactory"/>
    </bean>

    <tx:advice id="xxxTxAdvice" transaction-manager="xxxTransactionManager">   
        <tx:attributes>   
            <tx:method name="find*" isolation="READ_COMMITTED" read-only="true"/>
            <tx:method name="get*" isolation="READ_COMMITTED" read-only="true"/>
            <tx:method name="*" isolation="READ_COMMITTED" rollback-for="Throwable" />
        </tx:attributes>   
    </tx:advice>

    <aop:config>   
        <aop:pointcut id="xxxTxPointcut" expression="execution(* com.ims.service.xxx.impl..*BSImpl.*(..))"/>   
        <aop:advisor advice-ref="xxxTxAdvice" pointcut-ref="xxxTxPointcut" order="0"/>   
    </aop:config>   

    <bean id="xxxBaseDao" class="com.ims.persistence.dao.xxx.impl.XxxBaseDaoImpl">
        <property name="sessionFactory" ref="xxxSessionFactory"/>
    </bean> 

</beans>

View Code

  6. web.xml

    

 

 

View Code

  10. commons-lang3-3.5.jar

      BaseDaoImpl.java

图片 27图片 28

<?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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com" use-default-filters="false">
        <context:include-filter type="aspectj" expression="com.ims.web.controller..*Controller"/>
    </context:component-scan>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/view/" />
    </bean>
</beans>

    2.1. 工程的基础dao类

  注:ims全称:information management
system

  3. 点击此找到并下载
 Java SE Development Kit 6u45,推荐选拔三九位

  8. mysql-connector-java-5.1.40-bin.jar,mysql驱动包,可点击此下载

 

图片 29图片 30

    1.1. BaseController.java,工程的基本功controller类

  

jcl-over-slf4j-1.7.21.jar
slf4j-api-1.7.21.jar
slf4j-log4j12-1.7.21.jar
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.21.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.1.Final.jar

图片 31图片 32

相关文章