UserMapper
public interface UserMapper { // 查询全部用户 List<User> getUserList(); // 根据id查询用户 User getUserById(int id); // 添加用户 int addUser(User user); // 修改用户 int updateUser(User user); // 删除一个用户 int deleteUser(int id); }
UserMapper.xml文件
<insert id="addUser" parameterType="com.mine.pojo.User" > insert into mybatis.user(id, name, pwd) values (#{id},#{name},#{pwd}); </insert> <update id="updateUser" parameterType="com.mine.pojo.User"> update mybatis.user set name = #{name},pwd = #{pwd} where id = #{id}; </update> <delete id="deleteUser" parameterType="int"> delete from mybatis.user where id = #{id}; </delete>
注意事项:操作要和标签一一对应 update 对应update delete对应delete