MyBatisSSM 整合的匹配文件

 

1.1    maven项目pom管理

MyBatis 1MyBatis 2

  1 <!--常量和版本号-->
  2 <properties>
  3   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  4   <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  5   <commons.beanutils>1.9.3</commons.beanutils>
  6   <spring.version>4.3.2.RELEASE</spring.version>
  7   <aspectj.version>1.8.6</aspectj.version>
  8   <aspectj.weaver>1.8.6</aspectj.weaver>
  9   <mybatis.spring.version>1.3.0</mybatis.spring.version>
 10   <mybatis.version>3.4.5</mybatis.version>
 11   <mysql.version>5.1.32</mysql.version>
 12   <slf4j.version>1.7.25</slf4j.version>
 13   <slf4j.log4j12.version>1.7.25</slf4j.log4j12.version>
 14   <log4j.version>1.2.17</log4j.version>
 15   <log4j.core.version>2.3</log4j.core.version>
 16   <commons.logging.version>1.2</commons.logging.version>
 17   <junit.version>4.12</junit.version>
 18   <commons-fileupload.version>1.3.1</commons-fileupload.version>
 19   <druid.version>1.0.13</druid.version>
 20   <jstl.version>1.2</jstl.version>
 21   <jsp-api.version>2.0</jsp-api.version>
 22   <jackson.version>2.9.2</jackson.version>
 23 </properties>
 24 
 25 
 26 <dependencies>
 27   <!--数据连接池-->
 28   <dependency>
 29     <groupId>com.alibaba</groupId>
 30     <artifactId>druid</artifactId>
 31     <version>${druid.version}</version>
 32   </dependency>
 33 
 34   <dependency>
 35     <groupId>commons-beanutils</groupId>
 36     <artifactId>commons-beanutils</artifactId>
 37     <version>${commons.beanutils}</version>
 38   </dependency>
 39 
 40   <!-- spring-core -->
 41   <dependency>
 42     <groupId>org.springframework</groupId>
 43     <artifactId>spring-core</artifactId>
 44     <version>${spring.version}</version>
 45   </dependency>
 46 
 47   <!-- spring-context -->
 48   <dependency>
 49     <groupId>org.springframework</groupId>
 50     <artifactId>spring-context</artifactId>
 51     <version>${spring.version}</version>
 52   </dependency>
 53 
 54   <!-- Spring AOP -->
 55   <dependency>
 56     <groupId>org.springframework</groupId>
 57     <artifactId>spring-aop</artifactId>
 58     <version>${spring.version}</version>
 59   </dependency>
 60 
 61   <!-- AspectJ Runtime -->
 62   <dependency>
 63     <groupId>org.aspectj</groupId>
 64     <artifactId>aspectjrt</artifactId>
 65     <version>${aspectj.version}</version>
 66   </dependency>
 67 
 68   <!-- AspectJ Weaver -->
 69   <dependency>
 70     <groupId>org.aspectj</groupId>
 71     <artifactId>aspectjweaver</artifactId>
 72     <version>${aspectj.weaver}</version>
 73   </dependency>
 74 
 75   <!-- Spring Jdbc 的支持 -->
 76   <dependency>
 77     <groupId>org.springframework</groupId>
 78     <artifactId>spring-jdbc</artifactId>
 79     <version>${spring.version}</version>
 80   </dependency>
 81 
 82   <!-- SpringMVC -->
 83   <dependency>
 84     <groupId>org.springframework</groupId>
 85     <artifactId>spring-webmvc</artifactId>
 86     <version>${spring.version}</version>
 87   </dependency>
 88 
 89 
 90   <!-- mybatis-spring 整合 -->
 91   <dependency>
 92     <groupId>org.mybatis</groupId>
 93     <artifactId>mybatis-spring</artifactId>
 94     <version>${mybatis.spring.version}</version>
 95   </dependency>
 96 
 97   <!-- Jackson Json处理工具包 -->
 98   <dependency>
 99     <groupId>com.fasterxml.jackson.core</groupId>
100     <artifactId>jackson-databind</artifactId>
101     <version>${jackson.version}</version>
102   </dependency>
103 
104   <!-- mybatis -->
105   <dependency>
106     <groupId>org.mybatis</groupId>
107     <artifactId>mybatis</artifactId>
108     <version>${mybatis.version}</version>
109   </dependency>
110 
111 
112   <!-- MySql -->
113   <dependency>
114     <groupId>mysql</groupId>
115     <artifactId>mysql-connector-java</artifactId>
116     <version>${mysql.version}</version>
117   </dependency>
118 
119 
120 
121 
122   <!-- 文件上传组件 -->
123   <dependency>
124     <groupId>commons-fileupload</groupId>
125     <artifactId>commons-fileupload</artifactId>
126     <version>${commons-fileupload.version}</version>
127   </dependency>
128 
129   <!-- JSP相关 -->
130   <dependency>
131     <groupId>jstl</groupId>
132     <artifactId>jstl</artifactId>
133     <version>${jstl.version}</version>
134   </dependency>
135 
136   <dependency>
137     <groupId>javax.servlet</groupId>
138     <artifactId>jsp-api</artifactId>
139     <version>${jsp-api.version}</version>
140     <scope>provided</scope>
141   </dependency>
142 
143   <!-- Test dependencies -->
144   <dependency>
145     <groupId>junit</groupId>
146     <artifactId>junit</artifactId>
147     <version>${junit.version}</version>
148     <scope>test</scope>
149   </dependency>
150 </dependencies>
151 
152 <build>
153   <defaultGoal>install</defaultGoal>
154 
155   <plugins>
156     <plugin>
157       <groupId>org.apache.maven.plugins</groupId>
158       <artifactId>maven-compiler-plugin</artifactId>
159       <version>3.6.1</version>
160       <configuration>
161         <source>1.8</source>
162         <target>1.8</target>
163       </configuration>
164     </plugin>
165     <plugin>
166       <groupId>org.apache.maven.plugins</groupId>
167       <artifactId>maven-resources-plugin</artifactId>
168       <version>3.0.2</version>
169       <configuration>
170         <encoding>UTF-8</encoding>
171       </configuration>
172     </plugin>
173   </plugins>
174 
175   <!--IDEA编译src的java文件,而目录下的xml文件并不会一起打包,需要手动指定哪些配置文件需要读取-->
176   <resources>
177     <resource>
178       <directory>src/main/java</directory>
179       <includes>
180         <include>**/*.xml</include>
181       </includes>
182     </resource>
183   </resources>
184 </build>

View Code

1.2    Web.xml配置

MyBatis 3MyBatis 4

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xmlns="http://java.sun.com/xml/ns/javaee"
 4          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 5          id="WebApp_ID" version="3.0">
 6   <display-name>ssm</display-name>
 7 
 8   <!-- 编码过滤器 -->
 9   <filter>
10     <filter-name>characterEncoding</filter-name>
11     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
12 
13     <init-param>
14       <param-name>encoding</param-name>
15       <param-value>UTF-8</param-value>
16     </init-param>
17 
18     <init-param>
19       <param-name>forceEncoding</param-name>
20       <param-value>true</param-value>
21     </init-param>
22   </filter>
23 
24   <filter-mapping>
25     <filter-name>characterEncoding</filter-name>
26     <url-pattern>/*</url-pattern>
27   </filter-mapping>
28   <!--//End 编码过滤器 -->
29 
30 
31   <!-- 将POST请求转化为DELETE或者是PUT 要用_method指定真正的请求参数 -->
32   <filter>
33     <filter-name>HttpMethodFilter</filter-name>
34     <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
35   </filter>
36   <filter-mapping>
37     <filter-name>HttpMethodFilter</filter-name>
38     <url-pattern>/*</url-pattern>
39   </filter-mapping>
40 
41   <filter>
42     <filter-name>HiddenHttpMethodFilter</filter-name>
43     <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
44   </filter>
45   <filter-mapping>
46     <filter-name>HiddenHttpMethodFilter</filter-name>
47     <url-pattern>/*</url-pattern>
48   </filter-mapping>
49 
50   <!-- SpringMVC -->
51   <servlet>
52     <servlet-name>springmvc</servlet-name>
53     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
54 
55     <init-param>
56       <param-name>contextConfigLocation</param-name>
57       <param-value>classpath:springmvc.xml</param-value>
58     </init-param>
59     <load-on-startup>1</load-on-startup>
60   </servlet>
61   <servlet-mapping>
62     <servlet-name>springmvc</servlet-name>
63     <url-pattern>*.shtml</url-pattern>
64   </servlet-mapping>
65   <!-- //End SpringMVC -->
66 
67   <welcome-file-list>
68     <welcome-file>index.shtml</welcome-file>
69     <welcome-file>index.htm</welcome-file>
70     <welcome-file>index.jsp</welcome-file>
71     <welcome-file>default.html</welcome-file>
72     <welcome-file>default.htm</welcome-file>
73     <welcome-file>default.jsp</welcome-file>
74   </welcome-file-list>
75 </web-app>

View Code

1.3    springmvc配置文件

MyBatis 5MyBatis 6

 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:p="http://www.springframework.org/schema/p"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xmlns:mvc="http://www.springframework.org/schema/mvc"
 7        xsi:schemaLocation="
 8         http://www.springframework.org/schema/beans
 9         http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/context
11         http://www.springframework.org/schema/context/spring-context.xsd
12         http://www.springframework.org/schema/mvc
13         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
14 
15     <!-- 包扫描 -->
16     <context:component-scan base-package="cn.itcast"/>
17 
18 
19     <!--视图解析器配置-->
20     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
21         <property name="prefix" value="/WEB-INF/jsp/" />
22         <property name="suffix" value=".jsp" />
23     </bean>
24 
25     <!-- 文件上传解析器 -->
26     <bean id="multipartResolver"
27           class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
28         <!-- 最大允许上传文件大小,单位byte -->
29         <property name="maxUploadSize" value="100000000"/>
30     </bean>
31 
32 
33     <!--引入spring配置-->
34     <import resource="spring.xml" />
35 
36 </beans>

View Code

 

1.4    spring配置文件

MyBatis 7MyBatis 8

 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" xmlns:p="http://www.springframework.org/schema/p"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
 6        xmlns:aop="http://www.springframework.org/schema/aop"
 7        xsi:schemaLocation="
 8         http://www.springframework.org/schema/beans
 9         http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/context
11         http://www.springframework.org/schema/context/spring-context.xsd
12         http://www.springframework.org/schema/mvc
13         http://www.springframework.org/schema/mvc/spring-mvc.xsd
14         http://www.springframework.org/schema/tx
15         http://www.springframework.org/schema/tx/spring-tx.xsd
16         http://www.springframework.org/schema/aop
17         http://www.springframework.org/schema/aop/spring-aop.xsd">
18 
19     <!-- 解析jdbc配置文件 -->
20     <context:property-placeholder location="classpath:jdbc.properties" />
21 
22     <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean
23         below) 事务传播特性配置 -->
24     <tx:advice id="txAdvice" transaction-manager="txManager">
25         <!-- the transactional semantics... -->
26         <tx:attributes>
27             <tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"
28                        rollback-for="java.lang.Exception" />
29             <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"
30                        rollback-for="java.lang.Exception" />
31             <tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT"
32                        rollback-for="java.lang.Exception" />
33             <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"
34                        rollback-for="java.lang.Exception" />
35             <tx:method name="modify*" propagation="REQUIRED" isolation="DEFAULT"
36                        rollback-for="java.lang.Exception" />
37             <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"
38                        rollback-for="java.lang.Exception" />
39 
40             <!-- 查询方法 -->
41             <tx:method name="query*" read-only="true" />
42             <tx:method name="select*" read-only="true" />
43             <tx:method name="find*" read-only="true" />
44         </tx:attributes>
45     </tx:advice>
46 
47 
48     <!-- 配置事务管理器 -->
49     <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
50         <property name="dataSource" ref="dataSource" />
51     </bean>
52 
53 
54     <!-- 数据库基本信息配置 -->
55     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
56         <property name="driverClassName" value="${jdbc.driver}" />
57         <property name="url" value="${jdbc.url}" />
58         <property name="username" value="${jdbc.username}" />
59         <property name="password" value="${jdbc.pwd}" />
60     </bean>
61 
62     <!-- 声明式事务AOP配置 -->
63     <aop:config>
64         <aop:pointcut expression="execution(* cn.itcast.service.impl.*.*(..))" id="tranpointcut" />
65         <aop:advisor advice-ref="txAdvice" pointcut-ref="tranpointcut" />
66     </aop:config>
67 
68 
69     <!--SqlSessionFactoryBean的配置-->
70     <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
71         <!--
72             MyBatis别名
73             MyBatis配置文件
74             MyBatis配置映射文件
75             指定数据源
76          -->
77         <property name="typeAliasesPackage" value="cn.itcast.model" />
78         <property name="configLocation" value="classpath:mybatis.xml" />
79         <property name="mapperLocations">
80             <array>
81                 <value>classpath:cn/itcast/mapper/*Mapper.xml</value>
82             </array>
83         </property>
84         <property name="dataSource" ref="dataSource"/>
85     </bean>
86 
87 
88     <!--包扫描-->
89     <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
90         <!--指定对应接口的包路径-->
91         <property name="basePackage" value="cn.itcast.mapper" />
92         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean" />
93     </bean>
94 
95 
96 </beans>

View Code

1.5   JDBC配置文件

MyBatis 9MyBatis 10

1 jdbc.driver=com.mysql.jdbc.Driver
2 jdbc.url=jdbc:mysql://127.0.0.1:3306/crm?useUnicode=true&characterEncoding=utf8&autoReconnect=true
3 jdbc.username=root
4 jdbc.pwd=123456

View Code

1.6   Log4j配置文件

MyBatis 11MyBatis 12

1 log4j.rootLogger=DEBUG,A1
2 log4j.logger.com.taotao = DEBUG
3 log4j.logger.org.mybatis = DEBUG
4 
5 log4j.appender.A1=org.apache.log4j.ConsoleAppender
6 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
7 log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n

View Code

1.7    MyBatis配置文件

MyBatis 13MyBatis 14

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 </configuration>

View Code

 

网站地图xml地图