项目基于前博客。
在接口UserDao文件下添加接口:
void delUsers(List<UserModel> users);
在UserController下添加方法:
/**
* 批量删除用户信息
*/
@RequestMapping(value = "/delUsers", method = RequestMethod.GET)
public void delUsers(){
List<UserModel> list = new ArrayList<>();
UserModel user1 = new UserModel();
user1.setId(1);
list.add(user1);
UserModel user2 = new UserModel();
user2.setId(2);
list.add(user2);
userDao.delUsers(list);
}
在mapper的UserDAO.xml添加数据库sql:
<delete id="delUsers" parameterType="java.util.List">
DELETE FROM user_first WHERE id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item.id}
</foreach>
</delete>
测试成功!
网友评论