运行环境:maven + spring4.0.0 + mybatis3.2.4 + mybatis-spring1.2.2
一、编辑pom.xml配置文件,添加依赖:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.darren.framework.mybatis.mybatis-parent</groupId>
<artifactId>mybatis-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.darren.framework.mybatis.mybatis-spring</groupId>
<artifactId>mybatis-spring</artifactId>
<!-- 说明:由于该工程是另外一个项目的子模块,所有版本的定义都在那个项目的pom.xml里面,所以如果要单独使用该文件,需添加对应的版本号 -->
<dependencies>
<!-- spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<!-- mybatis spring支持 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- proxool -->
<dependency>
<groupId>com.cloudhopper.proxool</groupId>
<artifactId>proxool</artifactId>
</dependency>
<dependency>
<groupId>com.cloudhopper.proxool</groupId>
<artifactId>proxool-cglib</artifactId>
</dependency>
</dependencies>
</project>
二、创建实体类:User
package com.darren.models;
import java.io.Serializable;
public class User implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int uid;
private String userName;
private String password;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password