一、spring-web.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:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-4.0.xsd
  9. http://www.springframework.org/schema/mvc
  10. http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
  11.  
  12. <!-- 1.开启SpringMVC注解模式 -->
  13. <!--
  14. 简化配置:
  15. 1)自动注册DefaultAnnotationHandlerMapping、AnnotationMethodHandlerAdapter
  16. 2)提供一系列的:数据绑定、数字和日期的format(@NumberFormat、@DateTimeFormat)、xml、json默认读写支持
  17. -->
  18. <mvc:annotation-driven>
  19. <mvc:message-converters register-defaults="true">
  20. <!-- 配置Fastjson支持 -->
  21. <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" id="fastJsonHttpMessageConverter">
  22. <property name="supportedMediaTypes">
  23. <list>
  24. <value>text/html;charset=UTF-8</value>
  25. <value>application/json</value>
  26. </list>
  27. </property>
  28. <property name="features">
  29. <list>
  30. <value>WriteMapNullValue</value>
  31. <value>QuoteFieldNames</value>
  32. </list>
  33. </property>
  34. </bean>
  35. </mvc:message-converters>
  36. </mvc:annotation-driven>
  37.  
  38. <!-- 2.静态资源默认servlet配置 -->
  39. <!--
  40. 1)加入对静态资源的处理的支持(js、gif、png)
  41. 2)允许使用“/”做整体映射
  42. -->
  43. <mvc:default-servlet-handler/>
  44.  
  45. <!-- 3.配置jsp的视图解析器 -->
  46. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  47. <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
  48. <property name="prefix" value="/WEB-INF/jsp/"></property>
  49. <property name="suffix" value=".jsp"></property>
  50. </bean>
  51.  
  52. <!-- 4.扫描web相关的包 -->
  53. <context:component-scan base-package="com.demo.controller"/>
  54.  
  55. <!-- 5.文件上传 -->
  56. <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  57. <property name="defaultEncoding" value="utf-8"></property>
  58. <property name="maxUploadSize" value="32505856"></property>
  59. <property name="maxInMemorySize" value="4096"></property>
  60. </bean>
  61.  
  62. <!-- 6.拦截器 -->
  63. <bean id="demoInterceptor" class="com.aidilude.auction.interceptor.DemoInterceptor"/>
  64. <mvc:interceptors>
  65. <mvc:interceptor>
  66. <!-- 对所有的请求拦截使用/** ,对某个模块下的请求拦截使用:/myPath/* -->
  67. <mvc:mapping path="/**" />
  68. <ref bean="demoInterceptor" />
  69. </mvc:interceptor>
  70. </mvc:interceptors>
  71.  
  72. </beans>

二、spring-service.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:context="http://www.springframework.org/schema/context"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-4.0.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx.xsd">
  12.  
  13. <!-- 1.配置扫描service包下的所有使用注解的类 -->
  14. <context:component-scan base-package="com.demo.service"></context:component-scan>
  15.  
  16. <!-- 2.配置事务管理器 -->
  17. <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  18. <property name="dataSource" ref="dataSource"></property>
  19. </bean>
  20.  
  21. <!-- 3.配置使用注解管理事务 -->
  22. <tx:annotation-driven transaction-manager="txManager"/>
  23.  
  24. </beans>

三、spring-dao.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:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  9.  
  10. <!-- 1.引入db.properties -->
  11. <context:property-placeholder location="classpath:jdbc.properties"/>
  12. <!-- 2.配置数据源 -->
  13. <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
  14. init-method="init" destroy-method="close">
  15. <!-- 一、基本项: -->
  16. <property name="url" value="${jdbc.url}" />
  17. <property name="username" value="${jdbc.username}" />
  18. <property name="password" value="${jdbc.password}" />
  19.  
  20. <!-- 二、连接数量配置项: -->
  21. <!-- 2.1、初始化连接数
  22. 默认值:0
  23. -->
  24. <property name="initialSize" value="100" />
  25. <!-- 2.2、最大使用连接数
  26. 默认值:8
  27. -->
  28. <property name="maxActive" value="500" />
  29. <!-- 2.3、最小空闲连接数 -->
  30. <property name="minIdle" value="100" />
  31.  
  32. <!-- 三、连接测试项: -->
  33. <!-- 3.1、获取连接的最大等待时间(毫秒) -->
  34. <property name="maxWait" value="10000" />
  35. <!-- 3.2、用来检测连接是否有效的sql,select 1:返回1 -->
  36. <property name="validationQuery" value="select 1" />
  37. <!-- 3.3、申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
  38. 默认值:true
  39. -->
  40. <property name="testOnBorrow" value="true" />
  41. <!-- 3.4、归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
  42. 默认值:false
  43. -->
  44. <property name="testOnReturn" value="false" />
  45. <!-- 3.5、建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
  46. 默认值:false
  47. -->
  48. <property name="testWhileIdle" value="true" />
  49.  
  50. <!-- 四、Destory线程配置项: -->
  51. <!-- 4.1、Destory线程执行检测的时间间隔,检测需要关闭的空闲连接(毫秒) -->
  52. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  53. <!-- 4.2、Destory线程如果检测到当前连接的最后活跃时间和当前时间的差值大于minEvictableIdleTimeMillis,则关闭当前连接(毫秒) -->
  54. <property name="minEvictableIdleTimeMillis" value="300000" />
  55.  
  56. <!-- 五、remove线程项: -->
  57. <!-- 5.1、对于存活时间超过removeAbandonedTimeout的连接强制关闭 -->
  58. <property name="removeAbandoned" value="true" />
  59. <!-- 5.2、单位:秒 -->
  60. <property name="removeAbandonedTimeout" value="1800" />
  61. <!-- 5.3、关闭abanded连接时输出错误日志
  62. 默认值:false
  63. -->
  64. <property name="logAbandoned" value="true" />
  65.  
  66. <!-- 六、监控项: -->
  67. <!-- 6.1、监控数据库 -->
  68. <property name="filters" value="mergeStat" />
  69.  
  70. <!-- 七、选配项: -->
  71. <!-- 7.1、是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭
  72. 默认值:false
  73. <property name="poolPreparedStatements" value="true" />
  74. -->
  75. <!-- 7.2、每个连接上PSCache的大小 ,要配置必须大于0,当大于0了poolPreparedStatements自动触发为true
  76. 在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
  77. 默认值:-1
  78. <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
  79. -->
  80. </bean>
  81.  
  82. <!-- 3.配置SqlSessionFactory(SqlSessionFactoryBean) -->
  83. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  84. <!-- 注入数据源 -->
  85. <property name="dataSource" ref="dataSource"></property>
  86. <!-- 引入mybatis全局配置文件 -->
  87. <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  88. <!-- 扫描mapper映射文件 -->
  89. <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
  90. <!-- 扫描entity包,使用别名 -->
  91. <!-- 当定义了别名之后,就可以在入参或结果集中直接写类名(首字母大小写都可)了,而不用写全限定名 -->
  92. <property name="typeAliasesPackage" value=""></property>
  93. </bean>
  94. <!-- 4.扫描dao接口(MapperScannerConfigurer) -->
  95. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  96. <!-- 注入sqlSessionFactory(注意使用value引入) -->
  97. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  98. <!-- 配置dao接口位置 -->
  99. <property name="basePackage" value=""></property>
  100. </bean>
  101.  
  102. </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. <!-- 使用列别名替换列名,默认:true -->
  10. <!-- select name as label from table -->
  11. <setting name="useColumnLabel" value="true"/>
  12. <!-- 开启驼峰命名转换:Table(create_time) -> Entity(createTime) -->
  13. <setting name="mapUnderscoreToCamelCase" value="true"/>
  14. <!-- 将延迟加载设置为true -->
  15. <setting name="lazyLoadingEnabled" value="true"/>
  16. <!-- 将积极加载设置为false -->
  17. <setting name="aggressiveLazyLoading" value="false"/>
  18. <!-- 二级缓存的总开关 -->
  19. <!-- 还需要在指定的mapper映射文件中开启独立的开关 -->
  20. <setting name="cacheEnabled" value="false"/>
  21. </settings>
  22. </configuration>

五、mapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5.  
  6. <!-- mapper接口的全限定名 -->
  7. <mapper namespace="">
  8.  
  9. <!-- 当前mapper开启二级缓存,默认使用PerpetualCache,可整合redis分布式缓存等 -->
  10. <!-- 当开启二级缓存,别忘了将对象序列化(实现Serializable) -->
  11. <!-- 查看日志中的缓存命中可以验证缓存是否成功开启 -->
  12. <!--
  13. <cache/>
  14. -->
  15.  
  16. <!-- sql片段 -->
  17. <sql id="">
  18. <if test="">
  19.  
  20. </if>
  21. <if test="">
  22. and id in
  23. <foreach collection="" item="" open="(" close=")" separator=",">
  24.  
  25. </foreach>
  26. </if>
  27. </sql>
  28.  
  29. <select id="" parameterType="" resultType="">
  30. <!-- <where>会去掉第一个条件的and,如果没有条件,那么去掉where -->
  31. <where>
  32. <!-- 引入代码片段 -->
  33. <include refid=""></include>
  34. </where>
  35. </select>
  36.  
  37. <!-- 声明结果映射,用于需要将列别名映射为po类的属性名 -->
  38. <resultMap type="" id="">
  39. <id column="" property=""/>
  40. <result column="" property=""/>
  41. <!-- association标签用于映射引用数据类型 -->
  42. <!-- property:指定属性名,javaType:指定类型(全路径) -->
  43. <association property="" javaType="">
  44. <id column="" property=""/>
  45. <result column="" property=""/>
  46. </association>
  47. <!-- collection标签用于映射集合数据类型 -->
  48. <!-- ofType:指定类型(全路径) -->
  49. <collection property="" ofType="">
  50. <id column="" property=""/>
  51. <result column="" property=""/>
  52. </collection>
  53. </resultMap>
  54.  
  55. <select id="" parameterType="" resultMap="">
  56.  
  57. </select>
  58.  
  59. </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. MariaDB 库的基本操作(2)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  2. Swift5 语言参考(三) 类型

    在Swift中,有两种类型:命名类型和复合类型.一个名为类型是当它的定义可以给出一个特定名称的类型.命名类型包括类,结构,枚举和协议.例如,名为的用户定义类的实例MyClass具有该类型MyClass ...

  3. 设计模式《JAVA与模式》之调停者模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述调停者(Mediator)模式的: 调停者模式是对象的行为模式.调停者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显引用.从 ...

  4. EF 通过修改模版 更改生成实体名称

    直接修改T4 模版中对应关系就可以了,我这里是去掉了表中的“_”

  5. POJ 2545

    #include<iostream> #include<stdio.h> #include<iomanip> #define MAXN 100000 using n ...

  6. FineBI学习系列之FineBI的ETL处理(图文详解)

    不多说,直接上干货! 这是来自FineBI官网提供的帮助文档 http://help.finebi.com/http://help.finebi.com/doc-view-48.html 目录: 1. ...

  7. C++学习知识点

    所谓的学习,知识只是一部分,理解知识是如何被抽象和提炼的过程,才是更重要的 1.c++代码里面的\(反斜杠) C语言的宏要求只能在同一行,是不能跨行的.这里的反斜杠就是告诉编译器,我这里虽然换行了,但 ...

  8. PHP设计模式:观察者模式

    示例代码详见https://github.com/52fhy/design_patterns 观察者模式 观察者模式(Observer)是对象的行为模式,又叫发布-订阅(Publish/Subscri ...

  9. Shell脚本 | 一键获取安卓应用活动名

    上篇文章提到,启动时间的计算需要用到应用启动页的活动名(Activity_Name). 如何获取活动名呢?通常有如下几种方式: 1.询问 Dev 同事 2.adb logcat ActivityMan ...

  10. Linux之SElinux安全上下文件(1)

    SELinux:Secure Enhanced Linux,是美国国家安全局(NSA=The National Security Agency)和SCC(Secure Computing Courpo ...