mybatis-spring整合

Posted 江南小俊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis-spring整合相关的知识,希望对你有一定的参考价值。

1. 配置jar包

Spring,mybatis,mybatis-spring,mysql等。。。

  1 <properties>
  2         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  4 
  5         <!-- spring版本号 -->
  6         <spring.version>4.2.5.RELEASE</spring.version>
  7 
  8         <!-- mybatis版本号 -->
  9         <mybatis.version>3.2.8</mybatis.version>
 10 
 11         <!-- mysql驱动版本号 -->
 12         <mysql-driver.version>5.1.29</mysql-driver.version>
 13 
 14         <!-- log4j日志包版本号 -->
 15         <slf4j.version>1.7.18</slf4j.version>
 16         <log4j.version>1.2.17</log4j.version>
 17 
 18     </properties>
 19 
 20 
 21     <dependencies>
 22         <!-- 数据库连接池包 -->
 23         <dependency>
 24             <groupId>com.mchange</groupId>
 25             <artifactId>c3p0</artifactId>
 26             <version>0.9.5-pre8</version>
 27         </dependency>
 28         <!-- 添加jstl依赖 -->
 29         <dependency>
 30             <groupId>jstl</groupId>
 31             <artifactId>jstl</artifactId>
 32             <version>1.2</version>
 33         </dependency>
 34 
 35         <dependency>
 36             <groupId>javax</groupId>
 37             <artifactId>javaee-api</artifactId>
 38             <version>7.0</version>
 39         </dependency>
 40 
 41         <!-- 添加junit4依赖 -->
 42         <dependency>
 43             <groupId>junit</groupId>
 44             <artifactId>junit</artifactId>
 45             <version>4.11</version>
 46             <!-- 指定范围,在测试时才会加载 -->
 47             <scope>test</scope>
 48         </dependency>
 49 
 50         <!-- 添加spring核心依赖 -->
 51         <dependency>
 52             <groupId>org.springframework</groupId>
 53             <artifactId>spring-core</artifactId>
 54             <version>${spring.version}</version>
 55         </dependency>
 56         <dependency>
 57             <groupId>org.springframework</groupId>
 58             <artifactId>spring-web</artifactId>
 59             <version>${spring.version}</version>
 60         </dependency>
 61         <dependency>
 62             <groupId>org.springframework</groupId>
 63             <artifactId>spring-oxm</artifactId>
 64             <version>${spring.version}</version>
 65         </dependency>
 66         <dependency>
 67             <groupId>org.springframework</groupId>
 68             <artifactId>spring-tx</artifactId>
 69             <version>${spring.version}</version>
 70         </dependency>
 71         <dependency>
 72             <groupId>org.springframework</groupId>
 73             <artifactId>spring-jdbc</artifactId>
 74             <version>${spring.version}</version>
 75         </dependency>
 76         <dependency>
 77             <groupId>org.springframework</groupId>
 78             <artifactId>spring-webmvc</artifactId>
 79             <version>${spring.version}</version>
 80         </dependency>
 81         <dependency>
 82             <groupId>org.springframework</groupId>
 83             <artifactId>spring-context</artifactId>
 84             <version>${spring.version}</version>
 85         </dependency>
 86         <dependency>
 87             <groupId>org.springframework</groupId>
 88             <artifactId>spring-context-support</artifactId>
 89             <version>${spring.version}</version>
 90         </dependency>
 91         <dependency>
 92             <groupId>org.springframework</groupId>
 93             <artifactId>spring-aop</artifactId>
 94             <version>${spring.version}</version>
 95         </dependency>
 96 
 97         <dependency>
 98             <groupId>org.springframework</groupId>
 99             <artifactId>spring-test</artifactId>
100             <version>${spring.version}</version>
101         </dependency>
102 
103         <!-- 添加mybatis依赖 -->
104         <dependency>
105             <groupId>org.mybatis</groupId>
106             <artifactId>mybatis</artifactId>
107             <version>${mybatis.version}</version>
108         </dependency>
109 
110         <!-- 添加mybatis/spring整合包依赖 -->
111         <dependency>
112             <groupId>org.mybatis</groupId>
113             <artifactId>mybatis-spring</artifactId>
114             <version>1.2.2</version>
115         </dependency>
116 
117         <!-- 添加mysql驱动依赖 -->
118         <dependency>
119             <groupId>mysql</groupId>
120             <artifactId>mysql-connector-java</artifactId>
121             <version>${mysql-driver.version}</version>
122         </dependency>
123         <!-- 添加数据库连接池依赖 -->
124         <dependency>
125             <groupId>commons-dbcp</groupId>
126             <artifactId>commons-dbcp</artifactId>
127             <version>1.2.2</version>
128         </dependency>
129 
130         <!-- 添加fastjson -->
131         <dependency>
132             <groupId>com.alibaba</groupId>
133             <artifactId>fastjson</artifactId>
134             <version>1.1.41</version>
135         </dependency>
136 
137         <!-- 添加日志相关jar包 -->
138         <dependency>
139             <groupId>log4j</groupId>
140             <artifactId>log4j</artifactId>
141             <version>${log4j.version}</version>
142         </dependency>
143         <dependency>
144             <groupId>org.slf4j</groupId>
145             <artifactId>slf4j-api</artifactId>
146             <version>${slf4j.version}</version>
147         </dependency>
148         <dependency>
149             <groupId>org.slf4j</groupId>
150             <artifactId>slf4j-log4j12</artifactId>
151             <version>${slf4j.version}</version>
152         </dependency>
153 
154         <!-- log end -->
155         <!-- 映入JSON -->
156         <dependency>
157             <groupId>org.codehaus.jackson</groupId>
158             <artifactId>jackson-mapper-asl</artifactId>
159             <version>1.9.13</version>
160         </dependency>
161         <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
162         <dependency>
163             <groupId>com.fasterxml.jackson.core</groupId>
164             <artifactId>jackson-core</artifactId>
165             <version>2.8.0</version>
166         </dependency>
167         <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
168         <dependency>
169             <groupId>com.fasterxml.jackson.core</groupId>
170             <artifactId>jackson-databind</artifactId>
171             <version>2.8.0</version>
172         </dependency>
173 
174         <dependency>
175             <groupId>commons-fileupload</groupId>
176             <artifactId>commons-fileupload</artifactId>
177             <version>1.3.1</version>
178         </dependency>
179 
180         <dependency>
181             <groupId>commons-io</groupId>
182             <artifactId>commons-io</artifactId>
183             <version>2.4</version>
184         </dependency>
185 
186         <dependency>
187             <groupId>commons-codec</groupId>
188             <artifactId>commons-codec</artifactId>
189             <version>1.9</version>
190         </dependency>
191 
192         <!-- https://mvnrepository.com/artifact/com.github.abel533/ECharts -->
193         <dependency>
194             <groupId>com.github.abel533</groupId>
195             <artifactId>ECharts</artifactId>
196             <version>3.0.0</version>
197         </dependency>
198 
199         <dependency>
200             <groupId>com.google.code.gson</groupId>
201             <artifactId>gson</artifactId>
202             <version>2.5</version>
203             <scope>compile</scope>
204             <optional>true</optional>
205         </dependency>
206 
207         <dependency>
208             <groupId>net.sf.jxls</groupId>
209             <artifactId>jxls-core</artifactId>
210             <version>1.0.5</version>
211         </dependency>
212         <dependency>
213             <groupId>org.mybatis.generator</groupId>
214             <artifactId>mybatis-generator-core</artifactId>
215             <version>1.3.2</version>
216         </dependency>
217     </dependencies>
218 
219     <build>
220         <plugins>
221             <plugin>
222                 <groupId>org.mybatis.generator</groupId>
223                 <artifactId>mybatis-generator-maven-plugin</artifactId>
224                 <version>1.3.2</version>
225

以上是关于mybatis-spring整合的主要内容,如果未能解决你的问题,请参考以下文章

mybatis-spring 整合

MyBatis-Spring整合之方式1

mybatis-spring整合

MyBatis-Spring整合之方式3

mybatis-spring整合过程中AbstractMethodError

Spring-整合Mybatis