package com.suchuanlin.pojo;
import lombok.Data;
@Data
public class User {
private Integer id;
private String username;
private String password;
}
2.编写UserMapper接口
package com.suchuanlin.mapper;
import com.suchuanlin.pojo.User;
import java.util.List;
public interface UserMapper {
int insert(User user);
int update(User user);
int delete(Integer id);
User selectById(Integer id);
List<User> selectAll();
}
3.编写UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.suchuanlin.mapper.UserMapper">
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
insert into user (username,password) values(#{username},#{password})
</insert>
<update id="update">
update user set username = #{username}, password = #{password} where id = #{id}
</update>
<delete id="delete">
delete from user where id = #{id}
</delete>
<select id="selectById" resultType="user">
select * from user where id = #{id}
</select>
<select id="selectAll" resultType="user">
select * from user
</select>
</mapper>