https://blog.csdn.net/cs_hnu_scw/article/details/80718467 链接 (分页插件的使用方法和步骤)

一、针对之前的配置文件,对相应的功能增加相应的配置文件,实现更复杂更优化的功能配置

(配置pom.xml的时候最后面的build标签是使用自动生成的代码插件)
首先在pom.xml配置文件中添加相应的jar

  1. <dependencies>
  2. <dependency>
  3. <groupId>junit</groupId>
  4. <artifactId>junit</artifactId>
  5. <version>3.8.1</version>
  6. <scope>test</scope>
  7. </dependency>
  8. <!-- spring核心框架依赖 -->
  9. <dependency>
  10. <groupId>org.springframework</groupId>
  11. <artifactId>spring-context</artifactId>
  12. <version>5.0.9.RELEASE</version>
  13. </dependency>
  14. <!-- spring的aop结合aspectj依赖 -->
  15. <dependency>
  16. <groupId>org.springframework</groupId>
  17. <artifactId>spring-aspects</artifactId>
  18. <version>5.0.9.RELEASE</version>
  19. </dependency>
  20. <!-- 引入springmvc基础依赖 -->
  21. <dependency>
  22. <groupId>org.springframework</groupId>
  23. <artifactId>spring-webmvc</artifactId>
  24. <version>5.0.9.RELEASE</version>
  25. </dependency>
  26. <!-- springmvc的转换支持json -->
  27. <dependency>
  28. <groupId>com.fasterxml.jackson.core</groupId>
  29. <artifactId>jackson-core</artifactId>
  30. <version>2.9.6</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>com.fasterxml.jackson.core</groupId>
  34. <artifactId>jackson-databind</artifactId>
  35. <version>2.9.6</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>com.fasterxml.jackson.core</groupId>
  39. <artifactId>jackson-annotations</artifactId>
  40. <version>2.9.6</version>
  41. </dependency>
  42. <!-- springmvc支持文件上传的依赖 -->
  43. <dependency>
  44. <groupId>commons-fileupload</groupId>
  45. <artifactId>commons-fileupload</artifactId>
  46. <version>1.3.3</version>
  47. </dependency>
  48. <!-- 引入数据库驱动依赖 -->
  49. <dependency>
  50. <groupId>mysql</groupId>
  51. <artifactId>mysql-connector-java</artifactId>
  52. <version>5.1.39</version>
  53. </dependency>
  54. <!-- 引入mybatis依赖 -->
  55. <dependency>
  56. <groupId>org.mybatis</groupId>
  57. <artifactId>mybatis</artifactId>
  58. <version>3.4.6</version>
  59. </dependency>
  60. <!-- spring统一事务管理依赖 -->
  61. <dependency>
  62. <groupId>org.springframework</groupId>
  63. <artifactId>spring-tx</artifactId>
  64. <version>5.0.9.RELEASE</version>
  65. </dependency>
  66. <!-- spring和mybatis的集成依赖包 -->
  67. <dependency>
  68. <groupId>org.mybatis</groupId>
  69. <artifactId>mybatis-spring</artifactId>
  70. <version>1.3.2</version>
  71. </dependency>
  72. <!-- 引入druid数据连接池框架 -->
  73. <dependency>
  74. <groupId>com.alibaba</groupId>
  75. <artifactId>druid</artifactId>
  76. <version>1.1.11</version>
  77. </dependency>
  78. <!-- 引入spring jdbc依赖 -->
  79. <dependency>
  80. <groupId>org.springframework</groupId>
  81. <artifactId>spring-jdbc</artifactId>
  82. <version>5.0.9.RELEASE</version>
  83. </dependency>
  84. <!-- mybatis自动分页插件依赖 -->
  85. <dependency>
  86. <groupId>com.github.pagehelper</groupId>
  87. <artifactId>pagehelper</artifactId>
  88. <version>5.1.6</version>
  89. </dependency>
  90. <!-- 引入log4j依赖 -->
  91. <dependency>
  92. <groupId>org.slf4j</groupId>
  93. <artifactId>slf4j-log4j12</artifactId>
  94. <version>1.7.25</version>
  95. </dependency>
  96. <!-- jstl的依赖包 -->
  97. <dependency>
  98. <groupId>javax.servlet</groupId>
  99. <artifactId>jstl</artifactId>
  100. <version>1.2</version>
  101. </dependency>
  102. <!-- servlet项目底层api依赖,一般这些依赖web服务器都具有,但是eclipse编译环境没有,所以这里scope=provided -->
  103. <dependency>
  104. <groupId>javax.servlet</groupId>
  105. <artifactId>javax.servlet-api</artifactId>
  106. <version>4.0.1</version>
  107. <scope>provided</scope>
  108. </dependency>
  109. <dependency>
  110. <groupId>javax.servlet.jsp</groupId>
  111. <artifactId>jsp-api</artifactId>
  112. <version>2.2</version>
  113. <scope>provided</scope>
  114. </dependency>
  115. <!-- 集成tk.mybatis -->
  116. <dependency>
  117. <groupId>tk.mybatis</groupId>
  118. <artifactId>mapper</artifactId>
  119. <version>3.4.0</version>
  120. </dependency>
  121. <!-- ehcache支持 -->
  122. <dependency>
  123. <groupId>net.sf.ehcache</groupId>
  124. <artifactId>ehcache</artifactId>
  125. <version>2.10.5</version>
  126. </dependency>
  127. <dependency>
  128. <groupId>org.springframework</groupId>
  129. <artifactId>spring-context-support</artifactId>
  130. <version>5.0.9.RELEASE</version>
  131. </dependency>
  132. <dependency>
  133. <groupId>org.mybatis.caches</groupId>
  134. <artifactId>mybatis-ehcache</artifactId>
  135. <version>1.1.0</version>
  136. </dependency>
  137. </dependencies>
  138. <build>
  139. <plugins>
  140. <plugin>
  141. <!-- 添加插件 -->
  142. <groupId>org.mybatis.generator</groupId>
  143. <artifactId>mybatis-generator-maven-plugin</artifactId>
  144. <version>1.3.2</version>
  145. <!-- executions的作用是使得该项目具有:mvn mybatis-generator:generate启动命令 -->
  146. <!-- 给插件添加依赖 -->
  147. <dependencies>
  148. <dependency>
  149. <groupId>mysql</groupId>
  150. <artifactId>mysql-connector-java</artifactId>
  151. <version>5.1.39</version>
  152. </dependency>
  153. <dependency>
  154. <groupId>tk.mybatis</groupId>
  155. <artifactId>mapper</artifactId>
  156. <version>3.4.0</version>
  157. </dependency>
  158. </dependencies>
  159. <!-- 给插件配置参数 -->
  160. <configuration>
  161. <!-- 生成代码配置文件的路径 -->
  162. <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
  163. <overwrite>true</overwrite>
  164. <verbose>true</verbose>
  165. </configuration>
  166. </plugin>
  167. <!-- 内置tomcat服务器插件 -->
  168. <plugin>
  169. <groupId>org.apache.tomcat.maven</groupId>
  170. <artifactId>tomcat7-maven-plugin</artifactId>
  171. <version>2.2</version>
  172. </plugin>
  173. </plugins>
  174. </build>

二、在接着配置web.xml配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  4. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  5. version="3.0">
  6. <display-name>Archetype Created Web Application</display-name>
  7. <!-- 用listener的方式引入spring容器 -->
  8. <listener>
  9. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  10. </listener>
  11. <!-- 配置spring的配置文件位置 -->
  12. <context-param>
  13. <param-name>contextConfigLocation</param-name>
  14. <param-value>classpath:spring.xml</param-value>
  15. </context-param>
  16. <!-- 配置spring web统一字符集编码设置 -->
  17. <filter>
  18. <filter-name>characterEncodingFilter</filter-name>
  19. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  20. <init-param>
  21. <param-name>encoding</param-name>
  22. <param-value>UTF-8</param-value>
  23. </init-param>
  24. </filter>
  25. <filter-mapping>
  26. <filter-name>characterEncodingFilter</filter-name>
  27. <url-pattern>/*</url-pattern>
  28. </filter-mapping>
  29. <!-- 权限校验filter -->
  30. <filter>
  31. <filter-name>privilageFilter</filter-name>
  32. <filter-class>com.zhiyou.bd28.filter.PrivilageFilter</filter-class>
  33. </filter>
  34. <filter-mapping>
  35. <filter-name>privilageFilter</filter-name>
  36. <url-pattern>/*</url-pattern>
  37. </filter-mapping>
  38. <!-- druid监控页面设置 -->
  39. <servlet>
  40. <servlet-name>DruidStatView</servlet-name>
  41. <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  42. <init-param>
  43. <param-name>profileEnable</param-name>
  44. <param-value>true</param-value>
  45. </init-param>
  46. <init-param>
  47. <param-name>resetEnable</param-name>
  48. <param-value>false</param-value>
  49. </init-param>
  50. <!-- 可选项 登陆的用户名和密码 -->
  51. <init-param>
  52. <param-name>loginUsername</param-name>
  53. <param-value> druid</param-value>
  54. </init-param>
  55. <init-param>
  56. <param-name>loginPassword</param-name>
  57. <param-value>druid</param-value>
  58. </init-param>
  59. </servlet>
  60. <servlet-mapping>
  61. <servlet-name>DruidStatView</servlet-name>
  62. <url-pattern>/druid/*</url-pattern>
  63. </servlet-mapping>
  64. <!-- 配置springmvc里的前端控制器DispatcherServlet -->
  65. <servlet>
  66. <servlet-name>springmvc</servlet-name>
  67. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  68. <!-- 给DispatcherServlet设置初始化参数 -->
  69. <init-param>
  70. <param-name>contextConfigLocation</param-name>
  71. <param-value>classpath:springmvc.xml</param-value>
  72. </init-param>
  73. <!-- springmvc的容器和servlet项目一起启动 -->
  74. <load-on-startup>1</load-on-startup>
  75. </servlet>
  76. <servlet-mapping>
  77. <servlet-name>springmvc</servlet-name>
  78. <url-pattern>/</url-pattern> <!-- 映射所有的用户请求,都交由DispatcherServlet处理 -->
  79. </servlet-mapping>
  80. </web-app>

三、接着配置spring.xml和springmvc.xml的相关配置文件

springmvc.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.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!-- 启动servlet WebApplicationContext的包扫描,应该只有controller、viewresolver等注解 -->
    <context:component-scan base-package="com.zhiyou.bd28.controller"></context:component-scan>

    <!-- 视图模板的参数配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <!-- 支持文件上传视图解析器 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--允许上传的文件最大大小  单位是byte-->
        <property name="maxUploadSize" value="60000000"/>
    </bean>
    <!-- 静态资源拦截配置 : -->
    <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>
    <mvc:resources mapping="/css/**" location="/js/" cache-period="31556926"/>
    <mvc:resources mapping="/image/**" location="/js/" cache-period="31556926"/>

    <!-- json自动转换解析配置,如果使用mvc标签需要改句配置,否则@Controller的类会加载失败 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>text/plain;charset=UTF-8</value>
                </list>
            </property>
            </bean>

            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
</beans>

spring.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 启动root WebApplicationContext的包扫描,dao层和service层的包应该再次被扫描 -->
    <context:component-scan base-package="com.zhiyou.bd28"></context:component-scan>

    <!-- 配置druid数据源 -->
       <context:property-placeholder location="classpath:jdbc.properties"/>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="filters" value="stat,wall"/>
        <property name="maxActive" value="20"/>
        <property name="initialSize" value="1"/>
        <property name="maxWait" value="60000"/>
        <property name="minIdle" value="1"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <property name="validationQuery" value="SELECT 'x'"/> <!-- 检查数据连接成功的语句 -->
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="proxyFilters">
            <list> <ref bean="stat-filter"/></list>
        </property>
    </bean>
    <!-- 可选项 druid监控统计bean 对应上文dataSource中的proxyFilters --> 
    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter"> 
        <property name="slowSqlMillis" value="1000" />
        <property name="logSlowSql" value="true" />
        <property name="mergeSql" value="true" />
    </bean>
    <!-- 引入mybatis的SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 引入druid连接池数据源 -->
        <property name="dataSource" ref="dataSource"></property>
        <property name="mapperLocations" value="classpath:com/zhiyou/bd28/dao/*Mapper.xml"/>
        <!-- 添加mybatis.xml配置文件的引入 -->
        <property name="configLocation" value="classpath:mybatis.xml"></property>
    </bean>
    <!-- 添加mapper Dao的扫描 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.zhiyou.bd28.dao"/>
    </bean>

    <!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--事务详情(事务通知/增强), 在aop筛选基础上,确定使用什么样的事务。例如:读写、只读等
        <tx:attributes> 用于配置事务详情(属性属性)
            <tx:method name=""/> 详情具体配置
                propagation 传播行为 , REQUIRED:必须;REQUIRES_NEW:必须是新的 read-only 是否是只读事物
                isolation 隔离级别 read-only 只读事物
    -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="select*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <!--支持基于注解的aspectj-->
    <aop:aspectj-autoproxy/>
    <!--AOP编程,切入点表达式 确定增强的连接器,从而获得切入点-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.zhiyou.bd28.service..*.*(..))"/>
    </aop:config>
    <!-- 引入tk.mybatis的通用map -->
    <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.zhiyou.bd28.dao"/>
    </bean>

    <!-- 引入spring-ehcache.xml -->
    <import resource="spring-ehcache.xml"/>
</beans>

四:如果使用全部别名

mybatis.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里面是一些mybatis的底层配置参数 -->
  <settings>
      <setting name="cacheEnabled" value="true"/> <!-- 开启mybatis的二级缓存 -->
      <setting name="logImpl" value="SLF4J"/>
      <setting name="mapUnderscoreToCamelCase" value="true"/>
      <setting name="lazyLoadingEnabled" value="true"/>
      <setting name="aggressiveLazyLoading" value="false"/>
  </settings>

  <!-- typeAliases用来配置mapper中引用的类型名称的简称(别名) -->
  <typeAliases>
      <!-- 通过包名称配置别名,该方法配置的别名就直接等于包下的类名(去掉包名称的部分)
                或者类名称首字母小写-->
      <package name="com.zhiyou.bd28.model"/>
  </typeAliases>

  <plugins>
      <!-- 添加pagehelper插件配置 -->
      <plugin interceptor="com.github.pagehelper.PageInterceptor">
          <property name="helperDialect" value="mysql"/>
      </plugin>
  </plugins>
</configuration>

五:对于相关的优化存储的话使用配置文件达到二级缓存的目的,减缓存储压力

spring-ehcache.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:cache="http://www.springframework.org/schema/cache"
    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/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd">
    <!--配置cache -->
    <cache:annotation-driven cache-manager="cacheManager" /><!--需要引入ehcache.jar 
        和 spring-context-support.jar -->
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcache" />
    </bean><!-- 引入刚才的配置文件,一定要看好路径 -->
    <bean id="ehcache"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml"></property>
    </bean>
</beans>

同时需要配置相关的ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="ehcache.xsd">
    <!-- java.io.tmpdir:Java临时目录。指定一个文件目录,当EhCache把数据写到硬盘上或者系统jvm内存时,将把数据写到这个文件目录下 -->
    <diskStore path="D:/cache"/>
    <!-- maxElementsInMemory:设置基于内存的缓存可存放对象的最大数目。  -->
    <!-- eternal:如果为true,表示对象永远不会过期,此时会忽略timeToIdleSeconds和timeToLiveSeconds属性,默认为false; -->
    <!-- timeToIdleSeconds: 设定允许对象处于空闲状态的最长时间,以秒为单位。当对象自从最近一次被访问后,如果处于空闲状态的时间超过了 -->
    <!-- timeToIdleSeconds属性值,这个对象就会过期。当对象过期,EHCache将把它从缓存中清空。只有当eternal属性为false,该属性才有效。 -->
    <!-- 如果该属性值为0,则表示对象可以无限期地处于空闲状态。  -->
    <!-- timeToLiveSeconds:设定对象允许存在于缓存中的最长时间,以秒为单位。当对象自从被存放到缓存中后,如果处于缓存中的时间超过了 timeToLiveSeconds属性值,这个对象就会过期。当对象过期,EHCache将把它从缓存中清除。只有当eternal属性为false,该属性才有效。如果该属性值为0,则表示对象可以无限期地存在于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性,才有意义。  -->
    <!-- overflowToDisk:如果为true,表示当基于内存的缓存中的对象数目达到了maxElementsInMemory界限后,会把益出的对象写到基于硬盘的缓存中。 -->

    <!-- 设定缓存的默认数据过期策略 -->
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            overflowToDisk="true"
            timeToIdleSeconds="10"
            timeToLiveSeconds="20"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"/>

    <!--  自定义缓存策略 -->
    <cache name="cachelist"
           maxElementsInMemory="1000"
           eternal="false"
           overflowToDisk="true"
           timeToIdleSeconds="10"
           timeToLiveSeconds="20"/>
</ehcache>

六、对于相应的数据库表单自动生成代码的配置文件

<?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>
  <properties resource="jdbc.properties"/>
  <context id="mysqltables" targetRuntime="MyBatis3" defaultModelType="flat">
    <property name="javaFileEncoding" value="UTF-8"/>
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>
      <plugin type="${mapper.plugin}">
        <property name="mappers" value="${mapper.Mapper}"/>
    </plugin>
    <jdbcConnection driverClass="${jdbc.driver}"
        connectionURL="${jdbc.url}"
        userId="${jdbc.username}"
        password="${jdbc.password}">
    </jdbcConnection>
    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <!-- 实体类的生成基本配置 -->
    <javaModelGenerator targetPackage="com.zhiyou.bd28.model" targetProject="src/main/java">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
    <!-- mapper.xml配置文件的路径等参数配置 -->
    <sqlMapGenerator targetPackage="com.zhiyou.bd28.dao"  targetProject="src/main/resources">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
    <!-- 配置mapper接口的代码生成路径 -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.zhiyou.bd28.dao"  targetProject="src/main/java">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>




    <!-- 每一个table标签代表着一个表的代码自动生成设置 -->
    <!-- 
    <table tableName="tb_user" domainObjectName="TbUser" >
      <property name="useActualColumnNames" value="false"/>
      <generatedKey column="user_id" sqlStatement="mysql" identity="true"/>
    </table>
    <table tableName="tb_role" domainObjectName="TbRole" >
      <property name="useActualColumnNames" value="false"/>
      <generatedKey column="role_id" sqlStatement="mysql" identity="true"/>
    </table>
    <table tableName="tb_function" domainObjectName="TbFunction" >
      <property name="useActualColumnNames" value="false"/>
      <generatedKey column="function_id" sqlStatement="mysql" identity="true"/>
    </table>
     -->
     <table tableName="table_test" domainObjectName="TableTest" >
      <property name="useActualColumnNames" value="false"/>
      <generatedKey column="t_id" sqlStatement="mysql" identity="true"/>
    </table>
  </context>
</generatorConfiguration>

相应的log4j.properties和jdbc.properties文件
log4j.properties

log4j.rootLogger=DEBUG, Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.org.apache.ibatis=INFO
log4j.logger.org.springframework.jdbc.datasource=INFO

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmtest28
jdbc.username=root
jdbc.password=123456

mapper.plugin=tk.mybatis.mapper.generator.MapperPlugin
mapper.Mapper=tk.mybatis.mapper.common.Mapper

相对应的配置文件结构图片如下:
ssm最终的配置文件 - 图1

注意:我们在加载一个bootstrap的时候配置文件里面拦截静态资源,这里的配置路径需要和你创建的项目路径保持一致:

ssm最终的配置文件 - 图2
ssm最终的配置文件 - 图3

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<!-- script -->
<%String path = request.getContextPath();%>
<script src="<%=path %>/js/jquery.js"></script>
<link href="<%=path %>/js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="<%=path %>/js/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>