数据库删除 ‹delete›

Exisi 2021-03-27 07:26:01
Categories: Tags:

 

public interface UsersMapper {

 

public Integer deleteUserById(Integer id);

 

}

 

 

 

<?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

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);

}

}