概述一、搭建项目开发环境1. 新建一个maven项目SpringMybatis,项目结构如下: 说明:src/main/java 存放java代码和映射文件: com.study.springmybatis.dao 存放mapper接口 com.study.springmybatis.mapper 存放mapper映射文件 com.study.springmybatis.model 存放pojo类 com.study.springmybatis.service 存放service接口和对应的实现类src/test/java存放测试代码src/main/resources 存放数据库配置文件和xml配置文件2. 在pom.xml文件引入spring和mybatis相关的依赖,这里用的是阿里的maven远程仓库http://maven.aliyun.com/nexus/content/groups/public/1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">3 <modelVersion>4.0.0</modelVersion>45 <groupId>com.study.springmybatis</groupId>6 <artifactId>SpringMybatis</artifactId>7 <version>0.0.1-SNAPSHOT</version>8 <packaging>jar</packaging>910 <name>SpringMybatis</name>11 <url>http://maven.apache.org</url>1213 <properties>14 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>15 </properties>1617 <dependencies>18 <!-- 添加Spring相关的依赖 begin-->19 <dependency>20 <groupId>org.springframework</groupId>21 <artifactId>spring-core</artifactId>22 <version>4.3.12.RELEASE</version>23 </dependency>2425 <dependency>26 <groupId>org.springframework</groupId>27 <artifactId>spring-context</artifactId>28 <version>4.3.12.RELEASE</version>29 </dependency>3031 <dependency>32 <groupId>org.springframework</groupId>33 <artifactId>spring-tx</artifactId>34 <version>4.3.12.RELEASE</version>35 </dependency>3637 <dependency>38 <groupId>org.springframework</groupId>39 <artifactId>spring-jdbc</artifactId>40 <version>4.3.12.RELEASE</version>41 </dependency>4243 <dependency>44 <groupId>org.springframework</groupId>45 <artifactId>spring-test</artifactId>46 <version>4.3.12.RELEASE</version>47 </dependency>4849 <dependency>50 <groupId>org.springframework</groupId>51 <artifactId>spring-aop</artifactId>52 <version>4.3.12.RELEASE</version>53 </dependency>5455 <dependency>56 <groupId>org.springframework</groupId>57 <artifactId>spring-beans</artifactId>58 <version>4.3.12.RELEASE</version>59 </dependency>6061 <dependency>62 <groupId>org.apache.geronimo.bundles</groupId>63 <artifactId>aspectjweaver</artifactId>64 <version>1.6.8_2</version>65 </dependency>66 <!-- 添加Spring相关的依赖 end-->6768 <!-- 添加mybatis的核心包 begin-->69 <dependency>70 <groupId>org.mybatis</groupId>71 <artifactId>mybatis</artifactId>72 <version>3.2.8</version>73 </dependency>74 <!-- 添加mybatis的核心包 end-->7576 <!-- 添加mybatis与Spring
整合的核心包 begin -->77 <dependency>78 <groupId>org.mybatis</groupId>79 <artifactId>mybatis-spring</artifactId>80 <version>1.2.0</version>81 </dependency>82 <!-- 添加mybatis与Spring整合的核心包 end -->8384 <!--数据库连接相关包 begin -->85 <dependency>86 <groupId>org.wisdom-framework</groupId>87 <artifactId>mysql-connector-java</artifactId>88 <version>5.1.34_1</version>89 </dependency>9091 <dependency>92 <groupId>commons-dbcp</groupId>93 <artifactId>commons-dbcp</artifactId>94 <version>1.4</version>95 </dependency>9697 <dependency>98 <groupId>commons-pool</groupId>99 <artifactId>commons-pool</artifactId>100 <version>1.6</version>101 </dependency>102103 <dependency>104 <groupId>c3p0</groupId>105 <artifactId>c3p0</artifactId>106 <version>0.9.1.2</version>107 </dependency>108 <!--数据库连接相关包 end -->109110 <!-- 其他附加包 begin-->118 <dependency>119 <groupId>commons-logging</groupId>120 <artifactId>commons-logging< 一、搭建项目开发环境
1. 新建一个maven项目SpringMybatis,项目结构如下:
说明:
src/main/java 存放java代码和映射文件:
com.study.springmybatis.dao 存放mapper接口
com.study.springmybatis.mapper 存放mapper映射文件
com.study.springmybatis.model 存放pojo类
com.study.springmybatis.service 存放service接口和对应的实现类
src/test/java存放测试代码
src/main/resources 存放数据库配置文件和xml配置文件
2. 在pom.xml文件引入spring和mybatis相关的依赖,这里用的是阿里的maven远程仓库http://maven.aliyun.com/nexus/content/groups/public/
4.0.0 com.study.springmybatis SpringMybatis 0.0.1-SNAPSHOT jar SpringMybatis http://maven.apache.org UTF-8 org.springframework spring-core 4.3.12.RELEASE org.springframework spring-context 4.3.12.RELEASE org.springframework spring-tx 4.3.12.RELEASE org.springframework spring-jdbc 4.3.12.RELEASE org.springframework spring-test 4.3.12.RELEASE org.springframework spring-aop 4.3.12.RELEASE org.springframework spring-beans 4.3.12.RELEASE org.apache.geronimo.bundles aspectjweaver 1.6.8_2