springboot
<?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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
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://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
</beans>
spring bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
mybatis mapper
<?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 namespace="">
</mapper>
mybatis 配置文件
<?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>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="jdbcTypeForNull" value="NULL"/>
<!--显式的指定每个我们需要更改的配置的值,即使ta是默认的。防止版本更新带来的问题 -->
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
</settings>
<databaseIdProvider type="DB_VENDOR">
<property name="MySQL" value="mysql"/>
<property name="Oracle" value="oracle"/>
<property name="SQL Server" value="sqlserver"/>
</databaseIdProvider>
</configuration>
mybatis generatorConfiguration配置数据库
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--引入数据库连接配置信息-->
<!--引用mybatis-generator驱动 已导入包,可以不用引用-->
<!--<classPathEntry location="E:\maven-repository\org\mybatis\generator\mybatis-generator-core\1.3.7\mybatis-generator-core-1.3.7.jar"/>-->
<!--context:
id:唯一标识
targetRuntime:运行时环境。MyBatis3DynamicSql(默认值)|MyBatis3|MyBatis3Simple
defaultModelType:生成对象类型。conditional|flat|hierarchical
-->
<context id="mysql_generator" defaultModelType="flat"
targetRuntime="MyBatis3">
<!--javaFileEncoding 设置生成的文件编码格式。不设置,使用平台默认编码-->
<property name="javaFileEncoding" value="UTF-8"/>
<!--targetJava8 设置生成的代码可以使用Java8+功能。默认值true-->
<property name="targetJava8" value="true"/>
<!--plugin 插件配置-->
<!--<plugin type=""></plugin>-->
<!--commentGenerator 注释相关设置 -->
<commentGenerator>
<!--设置 生成的代码是否包含注释 默认false 生成注释。 true:不生成注释-->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接配置 connectionFactory和jdbcConnection 标签二选一-->
<!--<connectionFactory>-->
<!--<property name="driverClass" value="${driver}"/>-->
<!--<property name="connectionURL" value="${url}"/>-->
<!--<property name="userId" value="${username}"/>-->
<!--<property name="password" value="${password}"/>-->
<!--</connectionFactory>-->
<!-- 数据库连接配置 connectionFactory和jdbcConnection 标签二选一-->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/SSM"
userId="root"
password="root"
/>
<!--Java类型解析器用于根据数据库列信息计算Java类型-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--定义Java模型生成器的属性
targetPackage:生成代码存放的package的位置
targetProject:生成的代码存放的项目路径
-->
<javaModelGenerator targetPackage="com.luguz.bean"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--mapper xml文件位置-->
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
<!-- enableSubPackages:是否让schema作为包的后缀 默认false -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!--mapper接口生成的位置 dao-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.luguz.dao" targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 默认false -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="emp_dept" domainObjectName="Dept"></table>
<table tableName="emp_user" domainObjectName="Employee"></table>
</context>
</generatorConfiguration>
springboot文件过滤
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
springMVC servelet配置
<?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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
">
<!-- 开启组件扫描 -->
<context:component-scan base-package="com.">
</context:component-scan>
<!--开启注解处理器-->
<context:annotation-config>
</context:annotation-config>
</beans>
springMVC web配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="3.1"
metadata-complete="false">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--字符编码过滤器 所有过滤器前面-->
<filter>
<filter-name>characterEncodingFilter</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>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--使用rest风格 键页面普通的post请求转为指定的 put delete等-->
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
swagger
<!-- swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>