web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<!-- 定义Spring MVC的前端控制器 -->
<servlet>
<servlet-name>UserManage</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/UserManage-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <!-- 让Spring MVC的前端控制器拦截所有请求 -->
<servlet-mapping>
<servlet-name>UserManage</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- ================Spring配置开始================ -->
<!-- 设置Spring容器加载配置文件的路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/spring-config.xml</param-value>
<!-- <param-value>classpath:/spring-*.xml</param-value> -->
</context-param> <!-- 配置Spring监听器,可以在容器启动时,加载contextConfigLocation的context-param节点的配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- ================Spring配置结束================ --> <!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener> <!-- 指定首页 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- 配置SESSION超时,单位是分钟 -->
<session-config>
<session-timeout>10</session-timeout>
</session-config> <!--如下此段编码设置必须在所有filter的前面,否则过滤器有可能不起作用。
设置编码方式为UTF-8,解决中文乱码问题。-->
<filter>
<filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

UserManage-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:mvc="http://www.springframework.org/schema/mvc"
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.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd"> <!-- spring可以自动去扫描base-pack下面的包或者子包下面的java文件,
如果扫描到有Spring的相关注解的类,则把这些类注册为Spring的bean -->
<context:component-scan base-package="org.usermanage.controller"/> <!-- 配置处理映射器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <!-- 配置处理器适配器-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> <!-- 视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--指定默认前缀,controller中直接写文件名即可-->
<property name="prefix" value="/WEB-INF/content/jsp/"></property>
</bean> <!--指定单独处理的资源,不经过DispatcherServlet-->
<mvc:annotation-driven/> <!--所有以html结尾的请求全部到指定目录下查询-->
<mvc:resources mapping="/*.html" location="WEB-INF/content/html/"></mvc:resources>
<mvc:resources mapping="/*.js" location="WEB-INF/content/js/"></mvc:resources>
<mvc:resources mapping="/*.css" location="WEB-INF/content/css/"></mvc:resources>
<mvc:resources mapping="/login/*.css" location="WEB-INF/content/css/login/"></mvc:resources> </beans>

spring-config.xml

<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" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 加载配置jdbc属性文件 -->
<!--MapperScannerConigurer实际是在解析加载bean定义阶段的,这个时候要是设置sqlSessionFactory的话,
PropertyPlaceholderConfigurer还没来得及替换定义中的变量,导致把表达式当作字符串复制了
修改如下:-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/config/jdbc.properties</value>
<!--要是有多个配置文件,只需在这里继续添加即可 -->
</list>
</property>
</bean> <!--配置c3p0连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--注入属性-->
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- c3p0连接池的私有属性 -->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!-- 关闭连接后不自动commit -->
<property name="autoCommitOnClose" value="false"/>
<!-- 获取连接超时时间 -->
<property name="checkoutTimeout" value="10000"/>
<!-- 当获取连接失败重试次数 -->
<property name="acquireRetryAttempts" value="2"/>
</bean> <!--SqlSessionFactoryBean配置-->
<bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--Mybatis配置文件,非必须-->
<property name="configLocation" value="WEB-INF/config/mybatis-config.xml"/>
<property name="dataSource" ref="dataSource"/>
<!--扫描mapper.xml文件的位置-->
<property name="mapperLocations" value="classpath:org/usermanage/mapper/*.xml"/>
</bean> <!-- 配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory,单个dataSource时可省略 -->
<!--<property name="sqlSessionFactoryBeanName" value="sqlsessionFactory"/>-->
<!-- 给出需要扫描Dao接口包 -->
<property name="basePackage" value="org.usermanage.mapper"/>
</bean> <!--扫描所有使用注解的类型,使用Annotation自动注册Bean-->
<context:component-scan base-package="org.usermanage"/> <!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 使用annotation注解方式配置事务 -->
<!--<tx:annotation-driven transaction-manager="transactionManager"/>--> </beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
<setting name="useGeneratedKeys" value="true"/> <!-- 使用列别名替换列名 默认:true -->
<setting name="useColumnLabel" value="true"/> <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings> <!--从外部配置文件导入jdbc信息-->
<!--<properties resource="config/jdbc.properties"></properties>--> <!--<environments default="development">-->
<!--<environment id="development">-->
<!--<transactionManager type="JDBC"/>-->
<!--<dataSource type="POOLED">-->
<!--<property name="driver" value="${driver}"/>-->
<!--<property name="url" value="${url}"/>-->
<!--<property name="username" value="${username}"/>-->
<!--<property name="password" value="${password}"/>-->
<!--</dataSource>-->
<!--</environment>-->
<!--</environments>--> <!--指定映射资源文件-->
<!--<mappers>-->
<!--<mapper resource="classpath:org/usermanage/mapper/UserMapper.xml"/>-->
<!--</mappers>--> </configuration>

jdbc.properties

# jdbc连接信息
driver=com.mysql.jdbc.Driver
#url=jdbc:mysql://192.168.184.130:3306/gxrdb
url=jdbc:mysql://10.15.1.200:3306/gxrdb?useUnicode=true&characterEncoding=utf8
username=root
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. vue v-for 遍历循环时的key值的报错

    问题如下: [Vue warn] Avoid using non-primitive value as key, use string/number value instead. non-primit ...

  2. [04] JSP标准动作

    1.概述 JSP规范中定义了一系列的标准动作,Web容器按照规范进行了实现,可以解析并执行标准动作.而标准动作使用的是标准的xml语法,看上去也比较直观易懂,下面来看一个结构例子: <jsp:a ...

  3. BZOJ4552 HEOI/TJOI2016 排序 线段树、二分答案

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4552 题意:给出一个$1$到$N$的全排列,对其进行$M$次排序,每次排序将区间$[l ...

  4. LiveCharts文档-3开始-7标签

    原文:LiveCharts文档-3开始-7标签 LiveCharts文档-3开始-7标签 Label就是Chart中表示数值的字符串,通常被放置在轴的位置和提示当中. 下图中的这些字符串显示的都是标签 ...

  5. [Socket]Socket文件传输

    1.Server import java.io.DataInputStream; import java.io.FileOutputStream; import java.io.IOException ...

  6. Asp.Net MVC 获取当前 Controller Action Area

    获取控制器名称: ViewContext.RouteData.Values["controller"].ToString(); 获取Action名称: ViewContext.Ro ...

  7. BTrace 初探

    BTrace 是一款java诊断工具,在解决现场问题的时候非常有用. 今天使用的时候碰到几个坑,先记录一下. 下载下来以后直接运行报错 root@iZ2ze89756yjbvq7le6obdZ:~/b ...

  8. item 8: 比起0和NULL更偏爱nullptr

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 先让我们看一些概念:字面上的0是一个int,不是一个指针.如果C+ ...

  9. jdbc操作根据bean类自动组装sql,天啦,我感觉我实现了hibernate

    场景:需要将从ODPS数仓中计算得到的大额可疑交易信息导入到业务系统的mysql中供业务系统审核.最简单的方式是用阿里云的组件自动进行数据同步了.但是本系统是开放是为了产品化,要保证不同环境的可移植性 ...

  10. 10 分钟理解 BFC 原理

    一.常见定位方案 在讲 BFC 之前,我们先来了解一下常见的定位方案,定位方案是控制元素的布局,有三种常见方案: 普通流 (normal flow) 在普通流中,元素按照其在 HTML 中的先后位置至 ...