- UsersMapper.java
public interface UsersMapper {
public Integer deleteUserById(Integer id);
}
- UsersMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC
"-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace="com.mybatis.dao.UsersMapper">
<delete id="deleteUserById" parameterType="Integer">
delete from user
where id=#{id}
</delete>
</mapper>
- Test.java
@Test
public void deleteUser(Integer id) {
SqlSession sqlSession=null;
Integer count=0;
try{
sqlSession=MyBatisUtil.createSqlSession();
int id=1;
count=sqlSession.getMapper(UsersMapper.class).delete(id);
sqlSession.commit();
System.out.println("count:"+count);
}catch(Exception e){
e.printStackTrace();
}finally{
MyBatisUtil.closeSqlSession(sqlSession);
}
}