SpringMVC+Hibernate全注解整合


SpringMVC+Hibernate全注解整合
    博客分类:
  • Spring
springmvc 
Java代码 复制代码  收藏代码
  1. package com.org.service.impl;  
  2.   
  3. import java.util.List;  
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7. import org.springframework.beans.factory.annotation.Autowired;  
  8. import org.springframework.stereotype.Service;  
  9.   
  10. import com.org.dao.UserDao;  
  11. import com.org.entity.User;  
  12. import com.org.service.UserService;  
  13.   
  14. /** 
  15.  *@Author:liangjilong 
  16.  *@Date:2014-2-25 
  17.  *@Version:1.0 
  18.  *@Description: 
  19.  */  
  20. @Service  
  21. public class UserServiceImpl implements UserService{  
  22.   
  23.     @Resource//@Autowired  
  24.     private  UserDao userDao;  
  25.       
  26.     public List<User> getListUsers() {  
  27.         return userDao.getListUsers();  
  28.     }  
  29.        
  30. }  

 

Java代码 复制代码  收藏代码
  1. package com.org.action;  
  2.   
  3. import java.util.List;  
  4.   
  5. import javax.annotation.Resource;  
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8.   
  9. import org.springframework.stereotype.Controller;  
  10. import org.springframework.web.bind.annotation.RequestMapping;  
  11. import org.springframework.web.servlet.ModelAndView;  
  12.   
  13. import com.org.entity.User;  
  14. import com.org.service.UserService;  
  15. import com.org.utils.servlet.ServletUtils;  
  16.   
  17. /** 
  18.  *@Author:liangjilong 
  19.  *@Date:2014-2-25 
  20.  *@Version:1.0 
  21.  *@Description: 
  22.  */  
  23. @Controller  
  24. public class UserController{  
  25.   
  26.     @Resource  
  27.     private UserService userService;   
  28.       
  29.     @RequestMapping(value="/userList1.do")  
  30.     public String geUserList1(HttpServletRequest request ,HttpServletResponse response) throws Exception {  
  31.         List<User> lists=userService.getListUsers();  
  32.         if(lists!=null){  
  33.             //request.setAttribute("userList", lists);  
  34.             ServletUtils.setRequestValue("userList", lists);  
  35.         }  
  36.         return "/user/userList";//user文件下的userList.jsp  
  37.     }  
  38.   
  39.       
  40.     @RequestMapping(value="/userList2.do")  
  41.     public ModelAndView geUserList2(HttpServletRequest request ,HttpServletResponse response) throws Exception {  
  42.         List<User> lists=userService.getListUsers();  
  43.         if(lists!=null){  
  44.             //request.setAttribute("userList", lists);  
  45.             ServletUtils.setRequestValue("userList", lists);  
  46.         }  
  47.           
  48.         return new ModelAndView("/user/userList");  
  49.     }  
  50.   
  51. }  

 

Java代码 复制代码  收藏代码
  1. package com.org.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import com.org.entity.User;  
  6.   
  7. /** 
  8.  *@Author:liangjilong 
  9.  *@Date:2014-2-25 
  10.  *@Version:1.0 
  11.  *@Description: 
  12.  */  
  13. public interface UserDao {  
  14.   
  15.     public List<User> getListUsers();  
  16.   
  17. }  

 

Java代码 复制代码  收藏代码
  1. package com.org.dao.impl;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.springframework.stereotype.Component;  
  6. import org.springframework.stereotype.Repository;  
  7.   
  8. import com.org.HibernateDaoImpl;  
  9. import com.org.dao.UserDao;  
  10. import com.org.entity.User;  
  11.   
  12. /** 
  13.  *@Author:liangjilong 
  14.  *@Date:2014-2-25 
  15.  *@Version:1.0 
  16.  *@Description: 
  17.  */  
  18.   
  19. @Repository//@Component  
  20. @SuppressWarnings("all")  
  21. public class UserDaoImpl extends HibernateDaoImpl implements UserDao {  
  22.    
  23.     public List<User> getListUsers() {  
  24.         String hql="From User";  
  25.         //List<User>  lists=hibernateTemplate.find(hql);//方法一  
  26.         List<User>  lists=getHibernateTemplate().find(hql);//方法二  
  27.         return lists;  
  28.     }  
  29.   
  30. }  

 

Java代码 复制代码  收藏代码
  1. package com.org.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import com.org.entity.User;  
  6.   
  7. /** 
  8.  *@Author:liangjilong 
  9.  *@Date:2014-2-25 
  10.  *@Version:1.0 
  11.  *@Description: 
  12.  */  
  13. public interface UserService {  
  14.     public List<User> getListUsers();  
  15.    
  16.   
  17. }  

 

Java代码 复制代码  收藏代码
  1. package com.org;  
  2.   
  3. import java.io.Serializable;  
  4. import java.sql.SQLException;  
  5. import java.util.ArrayList;  
  6. import java.util.Collection;  
  7. import java.util.Iterator;  
  8. import java.util.List;  
  9. import java.util.regex.Matcher;  
  10. import java.util.regex.Pattern;  
  11.   
  12. import javax.annotation.PostConstruct;  
  13. import javax.annotation.Resource;  
  14.   
  15. import org.apache.commons.lang3.StringUtils;  
  16. import org.hibernate.HibernateException;  
  17. import org.hibernate.Query;  
  18. import org.hibernate.Session;  
  19. import org.springframework.orm.hibernate3.HibernateCallback;  
  20. import org.springframework.orm.hibernate3.HibernateTemplate;  
  21. import org.springframework.orm.hibernate3.support.HibernateDaoSupport;  
  22. import org.springframework.util.CollectionUtils;  
  23. import org.springframework.util.ObjectUtils;  
  24.   
  25. public class HibernateDaoImpl extends HibernateDaoSupport implements  
  26.         IHibernateDao {  
  27.   
  28.     /** 
  29.      * 这个和整合ibatis是一样的 
  30.       */  
  31.     @Resource(name = "hibernateTemplate")  
  32.     protected HibernateTemplate hibernateTemplate;  
  33.   
  34.     @PostConstruct  
  35.     public void initHibernateTemplate() {  
  36.         super.setHibernateTemplate(hibernateTemplate);  
  37.     }  
  38.   
  39.     public Integer count(final String hql) {  
  40.         if (StringUtils.isEmpty(hql)) {  
  41.             throw new IllegalStateException("hql is null");  
  42.         }  
  43.         Object result = this.getHibernateTemplate().execute(  
  44.                 new HibernateCallback<Object>() {  
  45.                     public Object doInHibernate(Session session)  
  46.                             throws HibernateException, SQLException {  
  47.                         return session.createQuery(hql).uniqueResult();  
  48.                     }  
  49.                 });  
  50.         return ((Long) result).intValue();  
  51.     }  
  52.   
  53.     public int bulkUpdate(String queryString, Object[] values) {  
  54.         return getHibernateTemplate().bulkUpdate(queryString, values);  
  55.     }  
  56.   
  57.     public <E> void deleteAll(Collection<E> entities) {  
  58.         getHibernateTemplate().deleteAll(entities);  
  59.     }  
  60.   
  61.     public Integer count(final String hql, final Object... obj) {  
  62.         if (ObjectUtils.isEmpty(obj)) {  
  63.             return count(hql);  
  64.         } else {  
  65.             if (StringUtils.isEmpty(hql)) {  
  66.                 throw new IllegalStateException("hql is null");  
  67.             }  
  68.             Object result = this.getHibernateTemplate().execute(  
  69.                     new HibernateCallback<Object>() {  
  70.   
  71.                         public Object doInHibernate(Session session)  
  72.                                 throws HibernateException, SQLException {  
  73.                             Query query = session.createQuery(hql);  
  74.                             for (int i = 0; i < obj.length; i++) {  
  75.                                 query.setParameter(i, obj[i]);  
  76.                             }  
  77.                             return query.uniqueResult();  
  78.                         }  
  79.                     });  
  80.             return ((Long) result).intValue();  
  81.         }  
  82.     }  
  83.   
  84.     public <E> void delete(E entity) {  
  85.         getHibernateTemplate().delete(entity);  
  86.     }  
  87.   
  88.     public <E> boolean exist(Class<E> c, Serializable id) {  
  89.         if (get(c, id) != null)  
  90.             return true;  
  91.         return false;  
  92.     }  
  93.   
  94.     public <E> List<E> find(String queryString) {  
  95.         return getHibernateTemplate().find(queryString);  
  96.     }  
  97.   
  98.     public <E> List<E> find(Class<E> bean) {  
  99.         String hql = "FROM " + bean.getSimpleName();  
  100.         return find(hql);  
  101.     }  
  102.   
  103.     public List<?> find(String queryString, Object[] values) {  
  104.         if (ObjectUtils.isEmpty(values)) {  
  105.             return find(queryString);  
  106.         } else {  
  107.             return getHibernateTemplate().find(queryString, values);  
  108.         }  
  109.     }  
  110.   
  111.     public <E> E findUniqueEntity(final String queryString,  
  112.             final Object... params) {  
  113.         if (StringUtils.isEmpty(queryString)) {  
  114.             throw new IllegalStateException("queryString is null");  
  115.         }  
  116.         if (ObjectUtils.isEmpty(params)) {  
  117.             return (E) getHibernateTemplate().execute(  
  118.                     new HibernateCallback<Object>() {  
  119.                         public Object doInHibernate(Session session) {  
  120.                             return session.createQuery(queryString)  
  121.                                     .uniqueResult();  
  122.                         }  
  123.                     });  
  124.         } else {  
  125.             return (E) getHibernateTemplate().execute(  
  126.                     new HibernateCallback<Object>() {  
  127.                         public Object doInHibernate(Session session) {  
  128.                             Query query = session.createQuery(queryString);  
  129.   
  130.                             for (int i = 0; i < params.length; i++) {  
  131.                                 query.setParameter(i, params[i]);  
  132.                             }  
  133.                             return query.uniqueResult();  
  134.                         }  
  135.                     });  
  136.         }  
  137.     }  
  138.   
  139.     public <E> List<E> findByNamedQuery(String queryName) {  
  140.         if (StringUtils.isEmpty(queryName)) {  
  141.             throw new IllegalArgumentException("queryName is null");  
  142.         }  
  143.         return getHibernateTemplate().findByNamedQuery(queryName);  
  144.     }  
  145.   
  146.     public <E> List<E> findByNamedQuery(String queryName, Object... values) {  
  147.         if (ObjectUtils.isEmpty(values)) {  
  148.             return this.findByNamedQuery(queryName);  
  149.         }  
  150.         return getHibernateTemplate().findByNamedQuery(queryName, values);  
  151.     }  
  152.   
  153.     public <E> List<E> findByPage(final String hql, final Integer startRow,  
  154.             final Integer pageSize, final Object... params) {  
  155.         if (StringUtils.isEmpty(hql)) {  
  156.             throw new IllegalStateException("hql is null");  
  157.         }  
  158.         if (ObjectUtils.isEmpty(params)) {  
  159.             return getHibernateTemplate().executeFind(  
  160.                     new HibernateCallback<Object>() {  
  161.                         public Object doInHibernate(Session session) {  
  162.                             return session.createQuery(hql)  
  163.                                     .setFirstResult(startRow)  
  164.                                     .setMaxResults(pageSize).list();  
  165.                         }  
  166.                     });  
  167.         } else {  
  168.             return getHibernateTemplate().executeFind(  
  169.                     new HibernateCallback<Object>() {  
  170.                         public Object doInHibernate(Session session) {  
  171.                             Query query = session.createQuery(hql);  
  172.                             for (int i = 0; i < params.length; i++) {  
  173.                                 query.setParameter(i, params[i]);  
  174.                             }  
  175.                             return query.setFirstResult(startRow)  
  176.                                     .setMaxResults(pageSize).list();  
  177.                         }  
  178.                     });  
  179.         }  
  180.     }  
  181.   
  182.     public <E> E get(Class<E> entityClass, Serializable id) {  
  183.         this.getHibernateTemplate().setCacheQueries(true);  
  184.         return this.getHibernateTemplate().get(entityClass, id);  
  185.     }  
  186.   
  187.     public <E> Iterator<E> iterate(String queryString) {  
  188.         return getHibernateTemplate().iterate(queryString);  
  189.     }  
  190.   
  191.     public <E> Iterator<E> iterate(String queryString, Object... values) {  
  192.         return getHibernateTemplate().iterate(queryString, values);  
  193.     }  
  194.   
  195.     public <E> E load(Class<E> entityClass, Serializable id) {  
  196.         return getHibernateTemplate().load(entityClass, id);  
  197.     }  
  198.   
  199.     public <E> void persist(E entity) {  
  200.         getHibernateTemplate().persist(entity);  
  201.     }  
  202.   
  203.     public <E> void refresh(E entity) {  
  204.         getHibernateTemplate().refresh(entity);  
  205.     }  
  206.   
  207.     public <E> Serializable save(E entity) {  
  208.         if (entity == null) {  
  209.             throw new IllegalArgumentException("entity is null");  
  210.         }  
  211.         return getHibernateTemplate().save(entity);  
  212.     }  
  213.   
  214.     public <E> void saveOrUpdate(E entity) {  
  215.         getHibernateTemplate().saveOrUpdate(entity);  
  216.     }  
  217.   
  218.     public <E> void saveOrUpdateAll(Collection<E> entities) {  
  219.         getHibernateTemplate().saveOrUpdateAll(entities);  
  220.     }  
  221.   
  222.     public <E> void update(E entity) {  
  223.         getHibernateTemplate().update(entity);  
  224.     }  
  225.   
  226.     public <T> void updateAll(Collection<T> entities) {  
  227.         if (CollectionUtils.isEmpty(entities)) {  
  228.             throw new IllegalArgumentException("entities is null");  
  229.         }  
  230.         int i = 0;  
  231.         for (Object obj : entities) {  
  232.             if (i % 30 == 0) {  
  233.                 getHibernateTemplate().flush();  
  234.                 getHibernateTemplate().clear();  
  235.             }  
  236.             getHibernateTemplate().update(obj);  
  237.             i++;  
  238.         }  
  239.     }  
  240.   
  241.     public <E> void saveAll(Collection<E> entities) {  
  242.         if (CollectionUtils.isEmpty(entities)) {  
  243.             throw new IllegalArgumentException("entities is null");  
  244.         }  
  245.         int i = 0;  
  246.         for (E obj : entities) {  
  247.             if (i % 30 == 0) {  
  248.                 getHibernateTemplate().flush();  
  249.                 getHibernateTemplate().clear();  
  250.             }  
  251.             save(obj);  
  252.             i++;  
  253.         }  
  254.     }  
  255.   
  256.     public <E> List<E> findByPage(String queryString, PageModel pageModel,  
  257.             List<?> params) {  
  258.   
  259.         String hql = queryString;  
  260.         if (queryString.toLowerCase().indexOf("where") == -1) {  
  261.             Matcher m = Pattern.compile("and").matcher(queryString);  
  262.             if (m.find()) {  
  263.                 hql = m.replaceFirst("where");  
  264.             } else {  
  265.                 m = Pattern.compile("AND").matcher(queryString);  
  266.                 if (m.find()) {  
  267.                     hql = m.replaceFirst("WHERE");  
  268.                 }  
  269.             }  
  270.         }  
  271.         int fromIndex = hql.toLowerCase().indexOf("from");  
  272.         int orderIndex = hql.toLowerCase().indexOf("group by");  
  273.         String hqlCount = "select count(*) "  
  274.                 + hql.substring(fromIndex,  
  275.                         orderIndex > 0 ? orderIndex : hql.length());  
  276.         int totalCount = (params == null || params.isEmpty()) ? count(hqlCount)  
  277.                 : count(hqlCount, params.toArray());  
  278.         pageModel.setRecordCount(totalCount);  
  279.         if (totalCount == 0) {  
  280.             return new ArrayList<E>();  
  281.         }  
  282.         Object[] temps = (params == null || params.isEmpty()) ? new Object[] {}  
  283.                 : params.toArray();  
  284.         return this.findByPage(hql, pageModel.getStartRow(),  
  285.                 pageModel.getPageSize(), temps);  
  286.     }  
  287.   
  288. }  

 

 

 

Xml代码 复制代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:mvc="http://www.springframework.org/schema/mvc"   
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.     xmlns:context="http://www.springframework.org/schema/context"  
  6.     xmlns:aop="http://www.springframework.org/schema/aop"   
  7.     xmlns:tx="http://www.springframework.org/schema/tx"  
  8.     xmlns:oscache="http://www.springmodules.org/schema/oscache"  
  9.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  10.          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd   
  11.          http://www.springframework.org/schema/context  
  12.          http://www.springframework.org/schema/context/spring-context-3.1.xsd   
  13.          http://www.springframework.org/schema/aop   
  14.          http://www.springframework.org/schema/aop/spring-aop-3.1.xsd   
  15.          http://www.springframework.org/schema/tx   
  16.          http://www.springframework.org/schema/tx/spring-tx-3.1.xsd   
  17.          http://www.springmodules.org/schema/oscache   
  18.          http://www.springmodules.org/schema/cache/springmodules-oscache.xsd  
  19.          http://www.springframework.org/schema/mvc  
  20.          http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">  
  21.   
  22.     <!--  
  23.          对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能   
  24.          mvc:annotation-driven  
  25.     -->   
  26.     <mvc:annotation-driven/>  
  27.     <!-- 扫描包 -->  
  28.     <context:annotation-config/>    
  29.     <context:component-scan base-package="com.org.*" />  
  30.       
  31.     <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  32.         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />  
  33.           <property name="prefix" value="/jsp/" />  
  34.         <property name="suffix" value=".jsp" />    
  35.     </bean>  
  36.       
  37.     <!-- 配置jdbc -->  
  38.     <bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  
  39.         <property name="locations">  
  40.             <value>classpath:properties/jdbc.properties</value>  
  41.         </property>  
  42.     </bean>  
  43.     <!-- 配置數據源 -->  
  44.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  45.         destroy-method="close">  
  46.         <property name="driverClassName" value="${jdbc.driver}" />  
  47.         <property name="url" value="${jdbc.url}" />  
  48.         <property name="username" value="${jdbc.username}" />  
  49.         <property name="password" value="${jdbc.password}" />  
  50.         <!-- 连接池启动时的初始值 -->  
  51.         <property name="initialSize" value="1"/>    
  52.         <property name="maxActive" value="500"/>      
  53.         <property name="maxIdle" value="2"/>          
  54.         <property name="minIdle" value="1"/>   
  55.     </bean>  
  56.         <!-- 配置sessionFactory   
  57.         注解配置  
  58.             org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean  
  59.         配置形式:  
  60.             org.springframework.orm.hibernate3.LocalSessionFactoryBean  
  61.         -->  
  62.           
  63.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
  64.         <property name="dataSource" ref="dataSource" />  
  65.          <property name="packagesToScan">  
  66.             <list>  
  67.                 <value>com.org.entity</value>  
  68.             </list>  
  69.         </property>  
  70.            
  71.         <property name="hibernateProperties">  
  72.             <props>  
  73.                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>  
  74.                 <prop key="hibernate.show_sql">true</prop>  
  75.             </props>  
  76.         </property>  
  77.     </bean>  
  78.       
  79.     <!-- 配置hibernateTemplate -->  
  80.     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">  
  81.         <property name="sessionFactory" ref="sessionFactory" />  
  82.     </bean>  
  83.       
  84.     <bean id="transactionManager"  
  85.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  86.         <property name="sessionFactory" ref="sessionFactory" />  
  87.     </bean>  
  88.     <!-- Spring AOP config配置切点 -->    
  89.     <aop:config>  
  90.         <aop:pointcut expression="execution(public * com.org.service.*.*(..))"  
  91.             id="bussinessService" />  
  92.         <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" />  
  93.     </aop:config>  
  94.   
  95.     <!-- 配置那个类那个方法用到事务处理 -->  
  96.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  97.         <tx:attributes>  
  98.             <tx:method name="get*" read-only="true" />  
  99.             <tx:method name="add*" propagation="REQUIRED" />  
  100.             <tx:method name="update*" propagation="REQUIRED" />  
  101.             <tx:method name="delete*" propagation="REQUIRED" />  
  102.             <tx:method name="*" propagation="REQUIRED" />  
  103.         </tx:attributes>  
  104.     </tx:advice>  
  105.       
  106.       
  107. <!-- 这个映射配置主要是用来进行静态资源的访问 -->  
  108.  <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>   
  109.  <mvc:resources mapping="/resource/**" location="/resource/" />    
  110.  <mvc:resources mapping="/jsp/**" location="/jsp/" />   
  111.    
  112. </beans>  

 

Xml代码 复制代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <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">  
  3.  <!-- 
  4.         #####################################配置处理乱码##################################### 
  5.     -->  
  6.     <filter>  
  7.         <filter-name>encodingFilter</filter-name>  
  8.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  9.         <init-param>  
  10.             <param-name>encoding</param-name>  
  11.             <param-value>GBK</param-value>  
  12.         </init-param>  
  13.     </filter>  
  14.     <filter-mapping>  
  15.         <filter-name>encodingFilter</filter-name>  
  16.         <url-pattern>/*</url-pattern>  
  17.     </filter-mapping>  
  18.     <!--  
  19.         #####################################Spring MVC配置#################################  
  20.         application-servlet.xml,规定:xxx-servlet.xml  
  21.     -->  
  22.     <listener>  
  23.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  24.     </listener>  
  25.     <context-param>  
  26.        
  27.         <param-name>contextConfigLocation</param-name>  
  28.         <!--  
  29.             param-name必须要等于contextConfigLocation  
  30.             默认的配置  
  31.             <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>  
  32.         -->  
  33.         <param-value>classpath:spring-*.xml</param-value>  
  34.     </context-param>  
  35.   
  36.       
  37.     <servlet>  
  38.         <servlet-name>springMVC</servlet-name>  
  39.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  40.         <init-param>  
  41.             <param-name>contextConfigLocation</param-name>  
  42.             <param-value>classpath:spring-*.xml</param-value>  
  43.         </init-param>  
  44.         <load-on-startup>1</load-on-startup>  
  45.     </servlet>  
  46.     <servlet-mapping>  
  47.         <servlet-name>springMVC</servlet-name>  
  48.         <url-pattern>*.do</url-pattern>  
  49.     </servlet-mapping>  
  50.       
  51.     <!-- 
  52.         #####################################struts2配置####################################### 
  53.     -->  
  54.   
  55.     <!-- 此配置在使用struts2 -->  
  56.         <filter>   
  57.             <filter-name>struts2</filter-name>   
  58.             <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>   
  59.         </filter>   
  60.         <filter-mapping>   
  61.             <filter-name>struts2</filter-name>   
  62.             <url-pattern>/*</url-pattern>   
  63.         </filter-mapping>   
  64.     <!--  
  65.         ################################使用freemaker模板中启动JSPSupportServlet#############################  
  66.       
  67.     <servlet>  
  68.         <servlet-name>JspSupportServlet</servlet-name>  
  69.         <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>  
  70.         <load-on-startup>1</load-on-startup>  
  71.     </servlet>  
  72.     -->  
  73.   <welcome-file-list>  
  74.     <welcome-file>index.html</welcome-file>  
  75.     <welcome-file>index.htm</welcome-file>  
  76.     <welcome-file>index.jsp</welcome-file>  
  77.     <welcome-file>default.html</welcome-file>  
  78.     <welcome-file>default.htm</welcome-file>  
  79.     <welcome-file>default.jsp</welcome-file>  
  80.   </welcome-file-list>  
  81. </web-app>  

 


SpringMVC+Hibernate全注解整合_第1张图片
 
SpringMVC+Hibernate全注解整合_第2张图片
 
SpringMVC+Hibernate全注解整合_第3张图片
 

 源代码

你可能感兴趣的:(SpringMVC+Hibernate全注解整合)