web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  6. id="WebApp_ID" version="3.1">
  7. <!-- 定义Spring MVC的前端控制器 -->
  8. <servlet>
  9. <servlet-name>UserManage</servlet-name>
  10. <servlet-class>
  11. org.springframework.web.servlet.DispatcherServlet
  12. </servlet-class>
  13. <init-param>
  14. <param-name>contextConfigLocation</param-name>
  15. <param-value>/WEB-INF/config/UserManage-servlet.xml</param-value>
  16. </init-param>
  17. <load-on-startup>1</load-on-startup>
  18. </servlet>
  19.  
  20. <!-- 让Spring MVC的前端控制器拦截所有请求 -->
  21. <servlet-mapping>
  22. <servlet-name>UserManage</servlet-name>
  23. <url-pattern>/</url-pattern>
  24. </servlet-mapping>
  25.  
  26. <!-- ================Spring配置开始================ -->
  27. <!-- 设置Spring容器加载配置文件的路径 -->
  28. <context-param>
  29. <param-name>contextConfigLocation</param-name>
  30. <param-value>WEB-INF/config/spring-config.xml</param-value>
  31. <!-- <param-value>classpath:/spring-*.xml</param-value> -->
  32. </context-param>
  33.  
  34. <!-- 配置Spring监听器,可以在容器启动时,加载contextConfigLocation的context-param节点的配置文件 -->
  35. <listener>
  36. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  37. </listener>
  38. <!-- ================Spring配置结束================ -->
  39.  
  40. <!-- 防止Spring内存溢出监听器 -->
  41. <listener>
  42. <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  43. </listener>
  44.  
  45. <!-- 指定首页 -->
  46. <welcome-file-list>
  47. <welcome-file>index.jsp</welcome-file>
  48. </welcome-file-list>
  49.  
  50. <!-- 配置SESSION超时,单位是分钟 -->
  51. <session-config>
  52. <session-timeout>10</session-timeout>
  53. </session-config>
  54.  
  55. <!--如下此段编码设置必须在所有filter的前面,否则过滤器有可能不起作用。
  56. 设置编码方式为UTF-8,解决中文乱码问题。-->
  57. <filter>
  58. <filter-name>CharacterEncoding</filter-name>
  59. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  60. <init-param>
  61. <param-name>encoding</param-name>
  62. <param-value>UTF-8</param-value>
  63. </init-param>
  64. <init-param>
  65. <param-name>forceEncoding</param-name>
  66. <param-value>true</param-value>
  67. </init-param>
  68. </filter>
  69. <filter-mapping>
  70. <filter-name>CharacterEncoding</filter-name>
  71. <url-pattern>/*</url-pattern>
  72. </filter-mapping>
  73.  
  74. </web-app>

UserManage-servlet.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:mvc="http://www.springframework.org/schema/mvc"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  9. http://www.springframework.org/schema/mvc
  10. http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
  11. http://www.springframework.org/schema/context
  12. http://www.springframework.org/schema/context/spring-context-4.2.xsd">
  13.  
  14. <!-- spring可以自动去扫描base-pack下面的包或者子包下面的java文件,
  15. 如果扫描到有Spring的相关注解的类,则把这些类注册为Spring的bean -->
  16. <context:component-scan base-package="org.usermanage.controller"/>
  17.  
  18. <!-- 配置处理映射器 -->
  19. <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
  20.  
  21. <!-- 配置处理器适配器-->
  22. <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
  23.  
  24. <!-- 视图解析器 -->
  25. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  26. <!--指定默认前缀,controller中直接写文件名即可-->
  27. <property name="prefix" value="/WEB-INF/content/jsp/"></property>
  28. </bean>
  29.  
  30. <!--指定单独处理的资源,不经过DispatcherServlet-->
  31. <mvc:annotation-driven/>
  32.  
  33. <!--所有以html结尾的请求全部到指定目录下查询-->
  34. <mvc:resources mapping="/*.html" location="WEB-INF/content/html/"></mvc:resources>
  35. <mvc:resources mapping="/*.js" location="WEB-INF/content/js/"></mvc:resources>
  36. <mvc:resources mapping="/*.css" location="WEB-INF/content/css/"></mvc:resources>
  37. <mvc:resources mapping="/login/*.css" location="WEB-INF/content/css/login/"></mvc:resources>
  38.  
  39. </beans>

spring-config.xml

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6.  
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.  
  14. <!-- 加载配置jdbc属性文件 -->
  15. <!--MapperScannerConigurer实际是在解析加载bean定义阶段的,这个时候要是设置sqlSessionFactory的话,
  16. PropertyPlaceholderConfigurer还没来得及替换定义中的变量,导致把表达式当作字符串复制了
  17. 修改如下:-->
  18. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  19. <property name="locations">
  20. <list>
  21. <value>WEB-INF/config/jdbc.properties</value>
  22. <!--要是有多个配置文件,只需在这里继续添加即可 -->
  23. </list>
  24. </property>
  25. </bean>
  26.  
  27. <!--配置c3p0连接池-->
  28. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  29. <!--注入属性-->
  30. <property name="driverClass" value="${driver}"></property>
  31. <property name="jdbcUrl" value="${url}"></property>
  32. <property name="user" value="${username}"></property>
  33. <property name="password" value="${password}"></property>
  34. <!-- c3p0连接池的私有属性 -->
  35. <property name="maxPoolSize" value="30"/>
  36. <property name="minPoolSize" value="10"/>
  37. <!-- 关闭连接后不自动commit -->
  38. <property name="autoCommitOnClose" value="false"/>
  39. <!-- 获取连接超时时间 -->
  40. <property name="checkoutTimeout" value="10000"/>
  41. <!-- 当获取连接失败重试次数 -->
  42. <property name="acquireRetryAttempts" value="2"/>
  43. </bean>
  44.  
  45. <!--SqlSessionFactoryBean配置-->
  46. <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  47. <!--Mybatis配置文件,非必须-->
  48. <property name="configLocation" value="WEB-INF/config/mybatis-config.xml"/>
  49. <property name="dataSource" ref="dataSource"/>
  50. <!--扫描mapper.xml文件的位置-->
  51. <property name="mapperLocations" value="classpath:org/usermanage/mapper/*.xml"/>
  52. </bean>
  53.  
  54. <!-- 配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
  55. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  56. <!-- 注入sqlSessionFactory,单个dataSource时可省略 -->
  57. <!--<property name="sqlSessionFactoryBeanName" value="sqlsessionFactory"/>-->
  58. <!-- 给出需要扫描Dao接口包 -->
  59. <property name="basePackage" value="org.usermanage.mapper"/>
  60. </bean>
  61.  
  62. <!--扫描所有使用注解的类型,使用Annotation自动注册Bean-->
  63. <context:component-scan base-package="org.usermanage"/>
  64.  
  65. <!-- 事务配置 -->
  66. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  67. <property name="dataSource" ref="dataSource"/>
  68. </bean>
  69.  
  70. <!-- 使用annotation注解方式配置事务 -->
  71. <!--<tx:annotation-driven transaction-manager="transactionManager"/>-->
  72.  
  73. </beans>

mybatis-config.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6. <settings>
  7. <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
  8. <setting name="useGeneratedKeys" value="true"/>
  9.  
  10. <!-- 使用列别名替换列名 默认:true -->
  11. <setting name="useColumnLabel" value="true"/>
  12.  
  13. <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
  14. <setting name="mapUnderscoreToCamelCase" value="true"/>
  15. </settings>
  16.  
  17. <!--从外部配置文件导入jdbc信息-->
  18. <!--<properties resource="config/jdbc.properties"></properties>-->
  19.  
  20. <!--<environments default="development">-->
  21. <!--<environment id="development">-->
  22. <!--<transactionManager type="JDBC"/>-->
  23. <!--<dataSource type="POOLED">-->
  24. <!--<property name="driver" value="${driver}"/>-->
  25. <!--<property name="url" value="${url}"/>-->
  26. <!--<property name="username" value="${username}"/>-->
  27. <!--<property name="password" value="${password}"/>-->
  28. <!--</dataSource>-->
  29. <!--</environment>-->
  30. <!--</environments>-->
  31.  
  32. <!--指定映射资源文件-->
  33. <!--<mappers>-->
  34. <!--<mapper resource="classpath:org/usermanage/mapper/UserMapper.xml"/>-->
  35. <!--</mappers>-->
  36.  
  37. </configuration>

jdbc.properties

  1. # jdbc连接信息
  2. driver=com.mysql.jdbc.Driver
  3. #url=jdbc:mysql://192.168.184.130:3306/gxrdb
  4. url=jdbc:mysql://10.15.1.200:3306/gxrdb?useUnicode=true&characterEncoding=utf8
  5. username=root
  6. password=root

SSM三大框架整合配置(Spring+SpringMVC+MyBatis)的更多相关文章

  1. SSM三大框架整合(Spring+SpringMVC+MyBatis)

    一. 导包 18个必须的包 二.配置Spring MVC的web文件 <?xml version="1.0" encoding="UTF-8"?> ...

  2. 手动配置三大框架整合:Spring+Struts2+mybatis

    如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...

  3. SSM框架整合(Spring+SpringMVC+MyBatis+Oracle)

    1.开发环境搭建以及创建Maven Web项目 参看之前的博文[确保maven web项目不报错]:http://www.cnblogs.com/cainiaomahua/p/6306476.html ...

  4. SSM框架的配置Spring+Springmvc +Mybatis

    ssm框架是由spring mvc +spring+mybatis组成 快速阅读 通过spring的配置文件spring.xml,在servlet中指定spring mvc的配置文件spring-mv ...

  5. SSM框架整合(Spring + SpringMVC + MyBatis)

    搭建环境 使用Spring(业务层)整合其他的框架SpringMVC(表现层)和MyBatis(持久层) Spring框架 创建数据库表 CREATE DATABASE ssm; USE ssm; C ...

  6. 04_SSM框架整合(Spring+SpringMVC+MyBatis)

    [SSM的系统架构] [整合概述] 第一步: MyBatis和Spring整合,通过Spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在Spring中进行注册. 第二 ...

  7. SSM框架整合(注解)-Spring+SpringMVC+MyBatis+MySql

    准备工作: 下载整合所需的jar包 点击此处下载 使用MyBatis Generator生成dao接口.映射文件和实体类 如何生成 搭建过程: 先来看一下项目的 目录结构 1.配置dispatcher ...

  8. SSM简明教程:简单的十步教你搭建人生第一个SSM框架[ SSM框架整合教程(Spring+SpringMVC+MyBatis) ]

    SSM_BookSystem SSM框架基础 SSM_BookSystem ---> Hello CRUD 说明:本项目目前包含基础的CRUD 日期:2017-05-01 22:25:37 作者 ...

  9. SSM三大框架整合配置详解

    首先,导入框架所需要的全部jar包(此处省略...........) 第一步:先从mybatis框架开始 我们只需要在mybatis的核心配置文件sqlConfigXml里写上这么一段话,代表的是给p ...

随机推荐

  1. 最小生成树(图论)--3366lg【模版】

    题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N<=5000,M<= ...

  2. CTS 如何处理 gating clock 和 generated clock

    1. CTS 时会将 ICG cell 作为 implicit nostop pin 处理,直接穿透,以 ICG cell 后面的 sink 点作为真正的 sink 来长 tree 2. CTS 时会 ...

  3. Centos6.8配置HTTPS

    HTTPS服务http+openssl 环境要求:CA证书: 192.168.1.103网站服务器: 192.168.1.104客户端: 192.168.1.107 (linux图形化界面) 内核:( ...

  4. @synchronized深入理解

    @synchronized是线程同步锁,易用.可读性高. @synchronized(self) { 临界区 } 利用如下命令将其重写 clang -rewrite-objc file  得到C++实 ...

  5. Codeforces Hello 2019

    Hello 2019 手速场qwq 反正EGH太神仙了啊.jpg 考试的时候不会啊.jpg A 暴力.jpg #include <cstdio> #include <algorith ...

  6. CF908D New Year and Arbitrary Arrangement 期望、DP

    题目传送门 题意:给出正整数$pa,pb,k$,最开始你有一个空串,每一次你有$\frac{pa}{pa + pb}$的概率向串最后放一个$a$,有$\frac{pb}{pa + pb}$的概率向串最 ...

  7. wpf项目打开多个窗体在任务栏只有一个任务

    原文:wpf项目打开多个窗体在任务栏只有一个任务 如果在wpf里,在一个父窗体上打开子窗体,只在任务栏显示一个任务,不是qq聊天窗口俩人聊天人显示俩给那样,只能显示 一个 private void B ...

  8. Luogu P1306 斐波那契公约数

    这道题其实是真的数学巨佬才撸的出来的题目了 但如果只知道结论但是不知道推导过程的我感觉证明无望 首先这道题肯定不能直接搞,而且题目明确说明了一些方法的问题 所以就暗示我们直接上矩阵了啦 但是如果直接搞 ...

  9. CQOI2018简要题解

    CQOI2018简要题解 D1T1 破解 D-H 协议 题意 Diffie-Hellman 密钥交换协议是一种简单有效的密钥交换方法.它可以让通讯双方在没有事先约定密钥(密码)的情况下,通过不安全的信 ...

  10. 浅谈nornalize.css(含源码)

    Normalize.css是一种CSS reset的替代方案.经过@necolas和@jon_neal花了几百个小时来努力研究不同浏览器的默认样式的差异,这个项目终于变成了现在这样. 我们创造norm ...