1 映射文件XXMapper.xml语法:
<mapper namespace="cn.smbms.dao.user.UserMapper">
<select id="getUserList" …
……
</select>
</mapper>
1.1 namespace:命名空间
namespace的命名必须跟某个接口同名
1.2 id: 命名空间中唯一的标识符
接口中的方法与映射文件中的SQL语句id一一对应
1.3 parameterType: 参数类型
传入SQL语句的参数类型
1.4 resultType:返回值类型
SQL语句返回值类型的完整类名或别名
1.5 实战:
(1)导入库
(2)创建工程,目录
(3)pom.xml
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
(4)实体类
package cn.kgc.entity;
public class User {
private Integer id;
private String userCode;
private String userName;
private String userPassword;
private Integer gender;
private String birthday;
private String phone;
private String address;
private Integer userRole;
private Integer createdBy;
private String creationDate;
private Integer modifyBy;
private String modifyDate;
private String userRoleName;
public String getUserRoleName() {
return userRoleName;
}
public void setUserRoleName(String userRoleName) {
this.userRoleName = userRoleName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserCode() {
return userCode;
}
public void setUserCode(String userCode) {
this.userCode = userCode;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {