User表 :
Id username password roleId
com.pojo包
1.User.java
package com.hp.pojo;
public class User {
private int id;
private String username;
private String password;
private int roleId;
public User() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getRoleId() {
return roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password="
+ password + ", roleId=" + roleId + "]";
}
}
com.mapper包
1.UserMapper.java
package com.hp.mapper;
import java.awt.List;
import com.hp.pojo.User;
public interface UserMapper {
public User query(int id);
public List queryByName(String username);// 模糊查询
public void update(int id,String password);//根据id改密码
public void insert(int id ,String username,String password);
public void delete(int id);
}
2.UserMapper.xml
update User SET password = #{password},
where id = #{id}
INSERT INTO User(id,username,password ) VALUES (#{id},#{username}, #{password})
DELETE FROM User WHERE id = #{id}
mybatis-config.xml