Spring和Hibernate整合
来源:互联网 发布:c4d r17 mac安装教程 编辑:程序博客网 时间:2024/06/05 19:38
创建Java Web项目
修改web.xml,如下:
<filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>sitemesh</filter-name> <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/appCtx-*.xml</param-value> </context-param> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <error-page> <error-code>404</error-code> <location>/WEB-INF/views/404.jsp</location> </error-page>
WEB-INF下创建springmvc-servlet.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" xmlns:p="http://www.springframework.org/schema/p" 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"> <context:annotation-config></context:annotation-config> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean> <context:component-scan base-package="com.ais.cms"></context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <property name="maxUploadSize" value="10485760000"></property> <property name="maxInMemorySize" value="40960"></property> </bean> <bean id="exceptionResolver" class="com.ais.cms.controller.BaseController"> <property name="exceptionMappings"> <props> <prop key="com.ais.cms.exception.BusinessException">error</prop> <prop key="java.lang.Exception">error</prop> </props> </property> </bean></beans>
WEB-INF下创建appCtx-ssi.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" xmlns:p="http://www.springframework.org/schema/p" 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"> <!-- 配置sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"></ref> </property> </bean> <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> <!-- 定义Hibernate模板对象 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean></beans>
WEB-INF下创建sitemesh3.xml文件,内容如下:
<sitemesh> <mapping path="*.do" decorator="/layout/template.jsp"></mapping> <mapping path="/login.do" exclue="true"></mapping> <mapping path="/main.do" exclue="true"></mapping> <mapping path="/error.do" exclue="true"></mapping></sitemesh>
WebRoot或WebContent下创建layout文件夹,并添加template.jsp文件,内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <meta name="description" content=""> <meta name="author" content=""> <title><sitemesh:write property='title'></sitemesh:write></title> <sitemesh:write property="head"></sitemesh:write> <!-- Fixed navbar --> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="#">SB Admin v2.0 后台管理系统</a> </div> </div> </nav> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="col-xs-4"> </div> <div class="col-xs-8"> <sitemesh:write property="body"></sitemesh:write> </div> </div> </div> <footer class="footer"> <div class="container"> Copyright © 2012-2015 All Rights Reserved </div> </footer>
阅读全文
0 0
- 整合Spring和Hibernate
- Hibernate和Spring整合
- spring和hibernate整合
- Spring和Hibernate整合
- Spring和Hibernate整合
- spring和Hibernate 整合
- 整合Hibernate和Spring
- 整合Hibernate和Spring
- spring和Hibernate整合
- spring和hibernate整合
- Spring和Hibernate整合
- spring和hibernate整合
- Spring和hibernate整合
- Spring -- spring 和 hibernate 整合
- hibernate和spring的整合
- spring 和hibernate的整合
- Struts2-Spring和Hibernate整合
- hibernate和spring整合总结
- 提高mysql千万级大数据SQL查询优化30条经验(Mysql索引优化注意)
- 剑指offer面试题[58]-二叉树的下一个结点
- angular4实现鼠标悬停3d倾斜
- 购物车的二级列表全选单选
- Android 省去 类型转换findViewByid
- Spring和Hibernate整合
- js动态背景(蜘蛛网特效)
- 欢迎使用CSDN-markdown编辑器
- SVN
- shell学习笔记
- 博客关键词的手动添加方法
- Linux shell编程学习笔记(九) 流编辑
- Centos7下的Redis集群搭建与Jedis连接
- 测试MySQL NULL -- 'Y' 返回Empty Result的情况