一、spring-web.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:mvc="http://www.springframework.org/schema/mvc"
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-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 1.开启SpringMVC注解模式 -->
<!--
简化配置:
1)自动注册DefaultAnnotationHandlerMapping、AnnotationMethodHandlerAdapter
2)提供一系列的:数据绑定、数字和日期的format(@NumberFormat、@DateTimeFormat)、xml、json默认读写支持
-->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<!-- 配置Fastjson支持 -->
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" id="fastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json</value>
</list>
</property>
<property name="features">
<list>
<value>WriteMapNullValue</value>
<value>QuoteFieldNames</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> <!-- 2.静态资源默认servlet配置 -->
<!--
1)加入对静态资源的处理的支持(js、gif、png)
2)允许使用“/”做整体映射
-->
<mvc:default-servlet-handler/> <!-- 3.配置jsp的视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean> <!-- 4.扫描web相关的包 -->
<context:component-scan base-package="com.demo.controller"/> <!-- 5.文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="32505856"></property>
<property name="maxInMemorySize" value="4096"></property>
</bean> <!-- 6.拦截器 -->
<bean id="demoInterceptor" class="com.aidilude.auction.interceptor.DemoInterceptor"/>
<mvc:interceptors>
<mvc:interceptor>
<!-- 对所有的请求拦截使用/** ,对某个模块下的请求拦截使用:/myPath/* -->
<mvc:mapping path="/**" />
<ref bean="demoInterceptor" />
</mvc:interceptor>
</mvc:interceptors> </beans>

二、spring-service.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: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-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 1.配置扫描service包下的所有使用注解的类 -->
<context:component-scan base-package="com.demo.service"></context:component-scan> <!-- 2.配置事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 3.配置使用注解管理事务 -->
<tx:annotation-driven transaction-manager="txManager"/> </beans>

三、spring-dao.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"
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-4.0.xsd"> <!-- 1.引入db.properties -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 一、基本项: -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" /> <!-- 二、连接数量配置项: -->
<!-- 2.1、初始化连接数
默认值:0
-->
<property name="initialSize" value="100" />
<!-- 2.2、最大使用连接数
默认值:8
-->
<property name="maxActive" value="500" />
<!-- 2.3、最小空闲连接数 -->
<property name="minIdle" value="100" /> <!-- 三、连接测试项: -->
<!-- 3.1、获取连接的最大等待时间(毫秒) -->
<property name="maxWait" value="10000" />
<!-- 3.2、用来检测连接是否有效的sql,select 1:返回1 -->
<property name="validationQuery" value="select 1" />
<!-- 3.3、申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
默认值:true
-->
<property name="testOnBorrow" value="true" />
<!-- 3.4、归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
默认值:false
-->
<property name="testOnReturn" value="false" />
<!-- 3.5、建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
默认值:false
-->
<property name="testWhileIdle" value="true" /> <!-- 四、Destory线程配置项: -->
<!-- 4.1、Destory线程执行检测的时间间隔,检测需要关闭的空闲连接(毫秒) -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 4.2、Destory线程如果检测到当前连接的最后活跃时间和当前时间的差值大于minEvictableIdleTimeMillis,则关闭当前连接(毫秒) -->
<property name="minEvictableIdleTimeMillis" value="300000" /> <!-- 五、remove线程项: -->
<!-- 5.1、对于存活时间超过removeAbandonedTimeout的连接强制关闭 -->
<property name="removeAbandoned" value="true" />
<!-- 5.2、单位:秒 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 5.3、关闭abanded连接时输出错误日志
默认值:false
-->
<property name="logAbandoned" value="true" /> <!-- 六、监控项: -->
<!-- 6.1、监控数据库 -->
<property name="filters" value="mergeStat" /> <!-- 七、选配项: -->
<!-- 7.1、是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭
默认值:false
<property name="poolPreparedStatements" value="true" />
-->
<!-- 7.2、每个连接上PSCache的大小 ,要配置必须大于0,当大于0了poolPreparedStatements自动触发为true
在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
默认值:-1
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
-->
</bean> <!-- 3.配置SqlSessionFactory(SqlSessionFactoryBean) -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 引入mybatis全局配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 扫描mapper映射文件 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
<!-- 扫描entity包,使用别名 -->
<!-- 当定义了别名之后,就可以在入参或结果集中直接写类名(首字母大小写都可)了,而不用写全限定名 -->
<property name="typeAliasesPackage" value=""></property>
</bean>
<!-- 4.扫描dao接口(MapperScannerConfigurer) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory(注意使用value引入) -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<!-- 配置dao接口位置 -->
<property name="basePackage" value=""></property>
</bean> </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 -->
<!-- select name as label from table -->
<setting name="useColumnLabel" value="true"/>
<!-- 开启驼峰命名转换:Table(create_time) -> Entity(createTime) -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 将延迟加载设置为true -->
<setting name="lazyLoadingEnabled" value="true"/>
<!-- 将积极加载设置为false -->
<setting name="aggressiveLazyLoading" value="false"/>
<!-- 二级缓存的总开关 -->
<!-- 还需要在指定的mapper映射文件中开启独立的开关 -->
<setting name="cacheEnabled" value="false"/>
</settings>
</configuration>

五、mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- mapper接口的全限定名 -->
<mapper namespace=""> <!-- 当前mapper开启二级缓存,默认使用PerpetualCache,可整合redis分布式缓存等 -->
<!-- 当开启二级缓存,别忘了将对象序列化(实现Serializable) -->
<!-- 查看日志中的缓存命中可以验证缓存是否成功开启 -->
<!--
<cache/>
--> <!-- sql片段 -->
<sql id="">
<if test=""> </if>
<if test="">
and id in
<foreach collection="" item="" open="(" close=")" separator=","> </foreach>
</if>
</sql> <select id="" parameterType="" resultType="">
<!-- <where>会去掉第一个条件的and,如果没有条件,那么去掉where -->
<where>
<!-- 引入代码片段 -->
<include refid=""></include>
</where>
</select> <!-- 声明结果映射,用于需要将列别名映射为po类的属性名 -->
<resultMap type="" id="">
<id column="" property=""/>
<result column="" property=""/>
<!-- association标签用于映射引用数据类型 -->
<!-- property:指定属性名,javaType:指定类型(全路径) -->
<association property="" javaType="">
<id column="" property=""/>
<result column="" property=""/>
</association>
<!-- collection标签用于映射集合数据类型 -->
<!-- ofType:指定类型(全路径) -->
<collection property="" ofType="">
<id column="" property=""/>
<result column="" property=""/>
</collection>
</resultMap> <select id="" parameterType="" resultMap=""> </select> </mapper>

SSM整合的配置文件的更多相关文章

  1. ssm整合各配置文件

    ssm整合 1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns ...

  2. 基于Maven的SSM整合的web工程

    此文章主要有以下几个知识点: 一.如何创建 Maven的Web 工程 二.整合SSM(Spring,SpringMvc,Mybatis),包括所有的配置文件 三.用 mybatis 逆向工程生成对应的 ...

  3. 零基础学习java------39---------json格式交互,Restful(不懂),静态资源映射,SSM整合(ssm整合思想,application.xml文件详解(声明式事务管理),)

    一. json格式交互(知道) 1 . 回顾ajax基本语法 $.ajax({ url:"", // 请求的后台路径 data:{"":"" ...

  4. 整合ssm框架之配置文件

    原文:https://blog.csdn.net/zwyanqing/article/details/53039591 ssm整合 一.applicationContext.xml 1.配置数据源 & ...

  5. 如何配置-整合ssm框架之配置文件

    ssm整合 一.applicationContext.xml 1.配置数据源 <bean id="dataSource" class="org.springfram ...

  6. SSM框架的配置整合(包含配置文件代码)

    由于SSM框架学习都要去网上或者以前的项目拷贝相同的代码,所以我在此把自己用到的配置文件全放在这里,帮助自己,帮助别人 首先开始前导入依赖和处理静态资源导出问题 <dependencies> ...

  7. SSM整合-配置文件

    使用工具:maven.idea.jdk8.mysql.tomcat9.0 初学ssm框架,配置文件的配置目录:                                     其中genera ...

  8. Maven + 最新SSM整合

    . 1. 开发环境搭建 参考博文:Eclipse4.6(Neon) + Tomcat8 + MAVEN3.3.9 + SVN项目完整环境搭建 2. Maven Web项目创建 2.1. 2.2. 2. ...

  9. SSM整合配置

    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis) 使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...

随机推荐

  1. Maximum repetition substring(POJ - 3693)(sa(后缀数组)+st表)

    The repetition number of a string is defined as the maximum number \(R\) such that the string can be ...

  2. css居中小结

    从css入门就开始接触,无所不在的,一直备受争议的居中问题. css居中分为水平居中和垂直居中,水平居中方式也较为常见和统一,垂直居中的方法就千奇百怪了. 博客原文地址:Claiyre的个人博客 ht ...

  3. 第十三章 ReentrantLock 简介

    Java 5.0 提供的新的加锁机制:当内置加锁机制不适合时 , 作为一种可选择的高级功能 一个可重入的互斥锁 Lock,它具有与使用 synchronized 方法和语句所访问的隐式监视器锁相同的一 ...

  4. Nginx安装使用及与tomcat实现负载均衡

    1. 背景 基于nginx强大的功能,实现一种负载均衡,或是不停机更新程序等.nginx相比大家基本上都知道是什么来头了,具体的文章大家可以去搜索相关文章学习阅读,或是可以查看Nginx中文文档和Ng ...

  5. 手推SVM

    推不动了,改日再更!

  6. [Leetcode]下一个更大元素II

    题目 给定一个循环数组(最后一个元素的下一个元素是数组的第一个元素),输出每个元素的下一个更大元素.数字 x 的下一个更大的元素是按数组遍历顺序,这个数字之后的第一个比它更大的数,这意味着你应该循环地 ...

  7. (转)AIX7.1安装Nginx 1.13的方法

    原文:https://blog.csdn.net/lvshaorong/article/details/79401860 https://blog.csdn.net/lvshaorong/articl ...

  8. Mysql的优化一则

    目的在于这么一个sql语句: SELECT w.* FROM wallpaper w inner join wallpaper_category_relation r ON w.wallpaper_i ...

  9. 从学CodeSmith谈程序员学习方法

    一直觉得CodeSmith是个好东西,最近正好有点时间来研究下,其实以前也想学习怎么用,在博客园搜一下有很多介绍CodeSmith的文章,我就收藏过一个写得很详细的http://terrylee.cn ...

  10. 运行vue init webpack vueTest时报错

    前言:好久没动vue项目了,早上心血来潮.准备写一个项目,然后坚持在github更新,不为别的,只为养成一个习惯. 运行vue init webpack vueTest时,报了下面的错误: 当时我思考 ...