SSM的框架配置文件

Cheryl

SSM的相关配置文件


该配置是基于spring4.0的

Spring框架

applicationContext.xml
Spring框架的核心配置文件

<?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">
       
       <!-- 将TestDaoImpl托管给Spring,创建一个名为myBean的DAO实例 -->
       <bean id="myBean" class="dao.TestDaoImpl"/>
       
       <!-- 将TestDIServiceImpl类托管给Spring,由Spring创建对象,创建一个id名的对象 -->
       <bean id="testDIService" class="service.TestDIServiceImpl">
       <!-- 调用TestDIServiceImpl -->
              <property name="testDao" ref="myBean"/>
       </bean>
</beans>

aspectJ框架的xml配置文件 applicationContext .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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
       
    <!-- 定义目标对象 -->
    <bean id="testDao" class="dynamic.jdk.TestDaoImpl"/>
    <!-- 定义切面 -->
       <bean id="myAspect" class="aspectj.xml.MyAspect"/>
    <!-- AOP配置 -->
    <aop:config>
       <!-- 配置切面 -->
       <aop:aspect ref="myAspect">
              <!-- 配置切入点 -->
              <aop:pointcut expression="execution(* dynamic.jdk.*.*(..))" id="myPointCut"/>
              <aop:before method="before" pointcut-ref="myPointCut"/>
              <aop:after-returning method="afterReturning" pointcut-ref="myPointCut"/>
              <aop:around method="around" pointcut-ref="myPointCut"/>
              <aop:after-throwing method="except" pointcut-ref="myPointCut"/>
              <aop:after method="after" pointcut-ref="myPointCut"/>
       </aop:aspect>
    </aop:config>
</beans>

Spring MVC框架

springmvc-servlet.xml
控制层配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd
                        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">

       <bean name="/login" class="controller.LoginController"/>
   
       <bean name="/register" class="controller.RegisterController"/>
       <!--
       <context:component-scan base-package="com.example.controller"></context:component-scan>
    
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/plain;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <!--通过jackson将Responsebody注解返回的对象自动序列化成json对象-->
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp"></property>
       -->
</beans>

转发器DispatcherServlet中的web.xml
作为底层支撑的Servlet版本至少要在3.1以上

<?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_4_0.xsd"
       id="WebApp_ID" version="4.0">
       
       <display-name>SpringMVC</display-name>
       <servlet>
              <servlet-name>springmvc</servlet-name>
               <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
              <servlet-name>springmvc</servlet-name>
              <url-pattern>/</url-pattern>
       </servlet-mapping>
</web-app>

MyBatis框架

UserMapper.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">
<!-- namespace表示映射xml路径 -->
<mapper namespace="com.mybatis.mapper.UserMapper">
       <!-- 根据uid查询一个用户信息 -->
       <select id="selectUserById" parameterType="Integer"
              resultType="com.mybatis.po.MyUser">
              select * from user where uid = #{uid}
       </select>
       <select id="selectAllUser" resultType="com.mybatis.po.MyUser">
              select * from user   
       </select>
       <!-- 插入新用户 -->
       <insert id="addUser" parameterType="com.mybatis.po.MyUser">
              insert into user (uname,usex) values(#{uname},#{usex})
       </insert>
       <!-- 修改一个用户 -->
       <update id="updateUser" parameterType="com.mybatis.po.MyUser">
              update user set uname = #{uname}, usex = #{usex} where uid = #{uid}
       </update>
       <!-- 删除一个用户 -->
       <delete id="deleteUser" parameterType="Integer">
              delete from user where uid = #{uid}
       </delete>
</mapper>

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>
       <environments default="development">
              <environment id="development">
                     <transactionManager type="JDBC" />
                     <dataSource type="POOLED">
                           <property name="driver" value="com.mysql.jdbc.Driver"  />
                           <property name="url"  value="jdbc:mysql://localhost:3306/springtest?characterEncoding=utf8" />
                           <property name="username" value="root" />
                           <property name="password" value="root" />
                     </dataSource>
              </environment>
       </environments>
       <!-- 控制全局的mappers文件 -->
       <mappers>
              <!-- UserMapper路径 -->
              <mapper resource="com/mybatis/mapper/UserMapper.xml" />
       </mappers>
</configuration>

generatorConfig.xml

<?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="datasource.properties" />
    <!-- 由驱动包半自动化生成代码 -->
    <classPathEntry location="E:/MyProjects/mavenrepo/mysql-connector-java-5.1.38.jar"/>


    <context id="MysqlContext" targetRuntime="MyBatis3Simple"
             defaultModelType="flat">
        <property name="beginningDelimiter" value="`" />
        <property name="endingDelimiter" value="`" />
        <!-- 设置生成代码为utf-8 -->
        <property name="javaFileEncoding" value="UTF-8" />


        <!-- 生成 JavaBean 对象继承 Serializable 类 -->
        <plugin  type="org.mybatis.generator.plugins.SerializablePlugin" />


        <!-- 增加mybatis通用mapper 插件 -->
        <!--
        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers"  value="com.mmall.util.MyMapper" />
        </plugin>
        -->
        <!-- 去除所有注释 -->
        <commentGenerator> <property name="suppressAllComments"  value="true"/> </commentGenerator>


        <!-- jdbc连接数据库 -->
        <jdbcConnection driverClass="${db.driverClassName}"
                        connectionURL="${db.url}"
                        userId="${db.username}" password="${db.password}">
        </jdbcConnection>


        <!-- 生成模型(MyBatis实体类)的包名和位置(相对/绝对位置,推荐相对位置) -->
        <javaModelGenerator
                targetPackage="com.mmall.pojo"
                targetProject="./src/main/java">
            <property name="enableSubPackage" value="false" />
            <!-- 是否生成构造方法 -->
            <property name="constructorBased" value="true" />
            <property name="trimStrings" value="true" />
            <!-- 是否设置生成的Model对象不可改变,即不生成setter方法 -->
            <property name="immutable" value="false" />
        </javaModelGenerator>
        <!-- 生成映射文件(MyBatis的SQL语句的xml文件)包名和位置 -->
        <sqlMapGenerator targetPackage="mappers"
                         targetProject="./src/main/resources" >
        <!-- 生成DAO的包名和位置(配置mapper对应的Java映射类) -->
        <property name="enableSubPackage" value="false" />
        </sqlMapGenerator>
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.mmall.dao"
                             targetProject="./src/main/java" />
        <!-- 逆向生成表 -->
        <!-- 生成表1 -->
        <table tableName="mmall_user"  domainObjectName="User" enableCountByExample="false"  enableUpdateByExample="false" enableDeleteByExample="false"  enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
        <table tableName="mmall_product"  domainObjectName="Product" enableCountByExample="false"  enableUpdateByExample="false" enableDeleteByExample="false"  enableSelectByExample="false" selectByExampleQueryId="false">
            <columnOverride column="detail" jdbcType="VARCHAR" />
            <columnOverride column="detail" jdbcType="VARCHAR" />
        </table>
    </context>
</generatorConfiguration>

mybatis-generator的核心依赖

            <!-- mybatis-generator begin -->
            <!-- 保证生成的mybatis文件正常运行 -->
            <mybatis.version>3.2.5</mybatis.version>
            <!-- tk.mybatis 自动生成dao,pojo,xml映射文件 -->
            <tk.mybatis.version>3.4.6</tk.mybatis.version>
            <jdbc.driver.version>5.1.38</jdbc.driver.version>
            <!-- 自动下载的依赖 -->
            <persistence.version>1.0</persistence.version>
            <!-- 序列化插件需要 -->
            <mybatis.generator.version>1.3.5</mybatis.generator.version>
            <mapper.plugin>tk.mybatis.mapper.generator.MapperPlugin</mapper.plugin>
            <mapper.Mapper>tk.mybatis.mapper.common.Mapper</mapper.Mapper>
            <!-- mybatis-generator end -->

            <!-- mybatis-generator begin -->
            <!-- Begin: mybatis依赖 -->
            <!-- Begin: 数据库依赖包 -->
            <dependency>
                  <groupId>org.mybatis</groupId>
                  <artifactId>mybatis</artifactId>
                  <version>${mybatis.version}</version>
            </dependency>
            <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <version>${jdbc.driver.version}</version>
                  <scope>runtime</scope>
            </dependency>
            <!-- End: 数据库依赖包 -->
            <!-- End: mybatis依赖 -->
            <!-- 通用tk.mybatis依赖 -->
            <dependency>
                  <groupId>tk.mybatis</groupId>
                  <artifactId>mapper</artifactId>
                  <version>${tk.mybatis.version}</version>
            </dependency>
            <!-- mybatis-generator end -->

//MyMapper通用接口
/*

  • The MIT License (MIT)

*

  • Copyright (c) 2014-2016 abel533@gmail.com

*

  • Permission is hereby granted, free of charge, to any person obtaining a copy
  • of this software and associated documentation files (the "Software"), to deal
  • in the Software without restriction, including without limitation the rights
  • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  • copies of the Software, and to permit persons to whom the Software is
  • furnished to do so, subject to the following conditions:

*

  • The above copyright notice and this permission notice shall be included in
  • all copies or substantial portions of the Software.

*

  • THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  • AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  • THE SOFTWARE.

*/

package com.mmall.util;

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

/**

  • 继承自己的MyMapper

*

  • @author liuzh
  • @since 2015-09-06 21:53

*/
public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> {

//TODO
//FIXME 特别注意,该接口不能被扫描到,否则会出错

}
mybatis-generator的maven手动命令所需要的插件

<!-- mybatis-generate插件,maven必须 -->

              <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>${mybatis.generator.version}</version>
                    <configuration>
                          <configurationFile>generatorConfig.xml</configurationFile>
                          <verbose>true</verbose>
                          <overwrite>false</overwrite>
                    </configuration>
                    <dependencies>
                          <!-- mybatis-generator begin -->
                          <!-- Begin: mybatis依赖 -->
                          <dependency>
                                <groupId>org.mybatis</groupId>
                                <artifactId>mybatis</artifactId>
                                <version>${mybatis.version}</version>
                          </dependency>
                          <!-- End: mybatis依赖 -->
                          <!-- 通用tk.mybatis依赖 -->
                          <dependency>
                                <groupId>tk.mybatis</groupId>
                                <artifactId>mapper</artifactId>
                                <version>${tk.mybatis.version}</version>
                          </dependency>
                          <!-- Begin: 数据库依赖包 -->
                          <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>${jdbc.driver.version}</version>
                                <scope>runtime</scope>
                          </dependency>
                          <!-- End: 数据库依赖包 -->
                          <!-- mybatis-generator -->
                          <dependency>
                                <groupId>org.mybatis.generator</groupId>
                                <artifactId>mybatis-generator-core</artifactId>
                                <version>${mybatis.generator.version}</version>
                          </dependency>
                          <!-- mybatis-generator end -->
                    </dependencies>
              </plugin>

log4j.properties

# Global logging configuration 错误信息打印
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration... 对应的包打印追踪
log4j.logger.com.octupus = TRACE
# Console output... 打印格式
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

db.properties

jdbc.jdbcUrl=jdbc:mysql://localhost:3306/springtest
jdbc.driverClass=com.mysql.jdbc.Driver?useUnicode=true&characterEncoding=utf8
jdbc.user=root
jdbc.password=root

SSM模板整合框架配置文件

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
        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/tx  http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- 自动扫描 -->
    <context:component-scan base-package="com.ssmdemo.dao"/>
    <context:component-scan base-package="com.ssmdemo.service"/>
    <!-- 配置数据源 -->
    <bean id="dataSource"
           class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url"
                   value="jdbc:mysql://localhost:3306/gitchat_ssm_demo_db"/>
        <!-- 改为你的地址即可 -->
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>
    <!-- 配置mybatis的sqlSessionFactory -->
    <bean id="sqlSessionFactory"  class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 自动扫描mappers.xml文件 -->
             <property name="mapperLocations"  value="classpath:mappers/*.xml"></property>
        <!-- mybatis配置文件 -->
        <property name="configLocation"  value="classpath:mybatis-config.xml"></property>
    </bean>
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ssmdemo.dao"/>
        <property name="sqlSessionFactoryBeanName"  value="sqlSessionFactory"></property>
    </bean>
    <!-- (事务管理)transaction manager, use JtaTransactionManager for  global tx -->
    <bean id="transactionManager"
           class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 配置事务通知属性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!-- 定义事务传播属性 -->
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="upd*" propagation="REQUIRED"/>
            <tx:method name="edit*" propagation="REQUIRED"/>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="new*" propagation="REQUIRED"/>
            <tx:method name="set*" propagation="REQUIRED"/>
            <tx:method name="remove*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED"/>
            <tx:method name="change*" propagation="REQUIRED"/>
            <tx:method name="check*" propagation="REQUIRED"/>
            <tx:method name="get*" propagation="REQUIRED"  read-only="true"/>
            <tx:method name="search*" propagation="REQUIRED"  read-only="true"/>
            <tx:method name="find*" propagation="REQUIRED"  read-only="true"/>
            <tx:method name="load*" propagation="REQUIRED"  read-only="true"/>
            <tx:method name="*" propagation="REQUIRED" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <!-- 配置事务切面 -->
    <aop:config>
        <aop:pointcut id="serviceOperation"
                      expression="(execution(*  com.ssmdemo.service.*.*(..)))"/>
        <aop:advisor advice-ref="txAdvice"  pointcut-ref="serviceOperation"/>
    </aop:config>
</beans>
# Global logging configuration 错误信息打印
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration... 对应的包打印追踪
log4j.logger.com.ssmdemo = TRACE
# Console output... 打印格式
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration

    PUBLIC "-//mybatis.org//DTD//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
    

<configuration>

<typeAliases>
    <package name="com.ssmdemo.entity"/>
</typeAliases>

</configuration>

<?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.xsd">
    <!-- 使用注解的包,包括子集 -->
    <context:component-scan base-package="com.ssmdemo.controller"/>
    <!-- 视图解析器 -->
    <bean id="viewResolver"
           class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

<?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>
      <!-- <classPathEntry location="C:\path\mysqldrivername"/> -->
      <!-- 具体配置内容 -->
      <!-- <properties resource="application.properties" /> -->
      <context id="MysqlContext" targetRuntime="MyBatis3Simple"
            defaultModelType="flat">
            <property name="beginningDelimiter" value="`" />
            <property name="endingDelimiter" value="`" />
            <!-- 设置生成代码为utf-8 -->
            <property name="javaFileEncoding" value="UTF-8" />
            <!-- 生成 JavaBean 对象继承 Serializable 类 -->
            <plugin  type="org.mybatis.generator.plugins.SerializablePlugin" />
            
            <!-- 增加mybatis通用mapper 插件 -->
            <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
                  <property name="mappers"  value="com.ssmdemo.utils.MyMapper" />
            </plugin>
            <!-- 去除所有注释 -->
            <!-- <commentGenerator> <property name="suppressAllComments"  value="true"
                  /> </commentGenerator> -->
            <!-- jdbc连接数据库 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                  connectionURL="jdbc:mysql://localhost:3306/gitchat_ssm_demo_db?characterEncoding=utf8"
                  userId="root" password="root">
            </jdbcConnection>
            <!-- 生成模型(MyBatis实体类)的包名和位置(相对/绝对位置,推荐相对位置) -->
            <javaModelGenerator
                  targetPackage="com.ssmdemo.entity"
                  targetProject="csdn_ssmdemo">
                  <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!-- 生成映射文件(MyBatis的SQL语句的xml文件)包名和位置 -->
            <sqlMapGenerator targetPackage="mapper"
                  targetProject="csdn_ssmdemo" />
            <!-- 生成DAO的包名和位置(配置mapper对应的Java映射类) -->
            <javaClientGenerator type="XMLMAPPER"
                  targetPackage="com.ssmdemo.dao"
                  targetProject="csdn_ssmdemo" />
            <!-- 逆向生成表 -->
            <!-- 生成表1 -->
            <table tableName="tb_class_four"  domainObjectName="Description"
                  enableCountByExample="false"  enableUpdateByExample="false"
                  enableDeleteByExample="false"  enableSelectByExample="false"
                  selectByExampleQueryId="false">
            </table>
      </context>
</generatorConfiguration>  

SSM框架中的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_4_0.xsd"
   id="WebApp_ID" version="4.0">
     
<display-name>ssmdemo</display-name>
<!--Start 欢迎页-->
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--End 欢迎页-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--Start spring监听器 -->
<listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--End Start spring监听器 -->
<!--Start 编码过滤器 解决乱码问题-->
<filter>
    <filter-name>encodingFilter</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>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<!--End 编码过滤器 解决乱码问题-->
<!--Start spring mvc servlet-->
<servlet>
    <servlet-name>springMVC</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<!--End spring mvc servlet-->
<!--Start servlet-mapping -->
<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!--End servlet-mapping -->

</web-app>

logback的配置文件

<?xml version="1.0" encoding="UTF-8"?><configuration debug="true" scan="true" scanPeriod="1 seconds">

    <contextName>logback</contextName>
    <!--定义参数,后面可以通过${app.name}使用-->
    <property name="app.name" value="logback_test"/>
    <!--ConsoleAppender 用于在屏幕上输出日志-->
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <!--定义了一个过滤器,在LEVEL之下的日志输出不会被打印出来-->
        <!--这里定义了DEBUG,也就是控制台不会输出比ERROR级别小的日志-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
        <!-- encoder 默认配置为PatternLayoutEncoder -->
        <!--定义控制台输出格式-->
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n</pattern>
        </encoder>
    </appender>


    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--定义日志输出的路径-->
        <!--这里的scheduler.manager.server.home 没有在上面的配置中设定,所以会使用java启动时配置的值-->
        <!--比如通过 java -Dscheduler.manager.server.home=/path/to XXXX 配置该属性-->
        <file>${scheduler.manager.server.home}/logs/${app.name}.log</file>
        <!--定义日志滚动的策略-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--定义文件滚动时的文件名的格式-->
            <fileNamePattern>${scheduler.manager.server.home}/logs/${app.name}.%d{yyyy-MM-dd.HH}.log.gz
            </fileNamePattern>
            <!--60天的时间周期,日志量最大20GB-->
            <maxHistory>60</maxHistory>
            <!-- 该属性在 1.1.6版本后 才开始支持-->
            <totalSizeCap>20GB</totalSizeCap>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <!--每个日志文件最大100MB-->
            <maxFileSize>100MB</maxFileSize>
        </triggeringPolicy>
        <!--定义输出格式-->
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} [%file : %line] - %msg%n</pattern>
        </encoder>
    </appender>


    <!--root是默认的logger 这里设定输出级别是debug-->
    <root level="trace">
        <!--定义了两个appender,日志会通过往这两个appender里面写-->
        <appender-ref ref="stdout"/>
        <appender-ref ref="file"/>
    </root>


    <!--对于类路径以 com.example.logback 开头的Logger,输出级别设置为warn,并且只输出到控制台-->
    <!--这个logger没有指定appender,它会继承root节点中定义的那些appender-->
    <logger name="com.example.logback" level="warn"/>


    <!--通过 LoggerFactory.getLogger("mytest") 可以获取到这个logger-->
    <!--由于这个logger自动继承了root的appender,root中已经有stdout的appender了,自己这边又引入了stdout的appender-->
    <!--如果没有设置 additivity="false" ,就会导致一条日志在控制台输出两次的情况-->
    <!--additivity表示要不要使用rootLogger配置的appender进行输出-->
    <logger name="mytest" level="info" additivity="false">
        <appender-ref ref="stdout"/>
    </logger>
    
    <!--由于设置了 additivity="false" ,所以输出时不会使用rootLogger的appender-->
    <!--但是这个logger本身又没有配置appender,所以使用这个logger输出日志的话就不会输出到任何地方-->
    <logger name="mytest2" level="info" additivity="false"/></configuration>

SSM框架相关依赖

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- ssm框架 -->
        <spring.version>4.2.4.RELEASE</spring.version>
        <java.version>1.8</java.version>
        <jdbc.driver.version>5.1.38</jdbc.driver.version>
        <aspectj.version>1.7.4</aspectj.version>
        <javax.servlet-api.version>3.1.0</javax.servlet-api.version>
        <jsp-api.version>2.2</jsp-api.version>
        <jstl.version>1.2</jstl.version>
        <mybatis.version>3.2.5</mybatis.version>
        <mybatis-spring.version>1.2.2</mybatis-spring.version>
        <maven.test.skip>true</maven.test.skip>

        <!-- tk.mybatis 自动生成dao,pojo,xml映射文件 -->
        <tk.mybatis.version>3.4.6</tk.mybatis.version>
        <persistence.version>1.0</persistence.version>
        <jdbc.driver.version>5.1.38</jdbc.driver.version>
        <mybatis.generator.version>1.3.5</mybatis.generator.version>
        <mapper.plugin>tk.mybatis.mapper.generator.MapperPlugin</mapper.plugin>
        <mapper.Mapper>tk.mybatis.mapper.common.Mapper</mapper.Mapper>
    </properties>

    <dependencies>
        <!-- SSM框架begin -->
        <!-- Begin: spring依赖 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- End: spring依赖 -->

        <!-- Begin: springmvc依赖 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- End: springmvc依赖 -->

        <!-- Begin: mybatis依赖 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis-spring.version}</version>
        </dependency>
        <!-- End: mybatis依赖 -->

        <!-- Begin: 数据库依赖包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${jdbc.driver.version}</version>
            <scope>runtime</scope>
        </dependency>
        <!-- End: 数据库依赖包 -->

        <!-- Begin: aspectj相关jar包 -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <!-- End: aspectj相关jar包 -->

        <!-- Begin: Servlet相关依赖包 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet-api.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>${jsp-api.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <!-- End: Servlet相关依赖包 -->
            <!--文件上传-->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
    </dependency>
        <!-- SSM框架 end -->
        
        <!-- Begin: mybatis-generator -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>${mybatis.generator.version}</version>
        </dependency>
        <!-- 通用tk.mybatis依赖 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>${tk.mybatis.version}</version>
        </dependency>
        <!-- End: mybatis-generator -->
    </dependencies>

## mybatis-generatror插件

  <build>
       <finalName>mmall</finalName>
       <!--配置mybatis插件-->
       <plugins>
           <plugin>
               <groupId>org.mybatis.generator</groupId>
               <artifactId>mybatis-generator-maven-plugin</artifactId>
               <version>${mybatis.generator.version}</version>
               <configuration>
                   <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
                   <verbose>true</verbose>
                   <overwrite>true</overwrite>
               </configuration>
               <dependencies>
                   <!-- mybatis-generator begin -->
                   <!-- Begin: mybatis依赖 -->
                   <dependency>
                       <groupId>org.mybatis</groupId>
                       <artifactId>mybatis</artifactId>
                       <version>${mybatis.version}</version>
                   </dependency>
                   <!-- End: mybatis依赖 -->
                   <!-- 通用tk.mybatis依赖 -->
                   <dependency>
                       <groupId>tk.mybatis</groupId>
                       <artifactId>mapper</artifactId>
                       <version>${tk.mybatis.version}</version>
                   </dependency>
                   <!-- Begin: 数据库依赖包 -->
                   <dependency>
                       <groupId>mysql</groupId>
                       <artifactId>mysql-connector-java</artifactId>
                       <version>${jdbc.driver.version}</version>
                       <scope>runtime</scope>
                   </dependency>
                   <!-- End: 数据库依赖包 -->
                   <!-- mybatis-generator -->
                   <dependency>
                       <groupId>org.mybatis.generator</groupId>
                       <artifactId>mybatis-generator-core</artifactId>
                       <version>${mybatis.generator.version}</version>
                   </dependency>
                   <!-- mybatis-generator end -->
               </dependencies>
           </plugin>

           <!-- geelynote maven的核心插件之-complier插件默认只支持编译Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml里面加上 增加编译插件 -->
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <!--不加可能出错-->
               <version>3.8.0</version>
               <configuration>
                   <source>1.8</source>
                   <target>1.8</target>
                   <encoding>UTF-8</encoding>
                   <!-- 非常重要,用于导入支付宝的本地依赖,不配置的话上线会报异常 -->
                   <compilerArguments>
                       <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
                   </compilerArguments>
               </configuration>
           </plugin>
       </plugins>
阅读 1.2k

Java技术栈 [链接]

13 声望
0 粉丝
0 条评论

Java技术栈 [链接]

13 声望
0 粉丝
文章目录
宣传栏