思路如下
在你准备写假删除的表中加一个标记字段,例如加一个"delete_flag"来表示该条数据的状态,可以规定0未删1删除.

xml
<update id="deleteByIds">
update 表名 set delete_flag = 1
where id in
<foreach item="item" collection="ids" separator="," open="(" close=")" index="">
#{item}
</foreach>
</update>
用update来改变删除状态
注:
当传入参数为数组或者集合时需要通过<foreach></foreach>标签进行遍历
collection:指定输入对象中集合属性
item:每次遍历生成的对象
open:开始遍历时拼接的串
close:结束遍历时两个对象需要拼接的串
index:是当前 List 集合遍历次数的计数器
mapper
boolean deleteByIds(@Param("ids")List<Long> ids);
service
boolean deleteByIds(List<Long> ids);
service实现类
@Override
public boolean deleteByIds(List<Long> ids) {
if(ids != null){
if(***Mapper.deleteByIds(ids)){
return true;
}
}
return false;
}
controller
@GetMapping("/delete")
public ResultJson delete(@RequestParam("ids") Long[] ids){
boolean flag = ******Service.deleteByIds(Arrays.asList(ids));
return ResultJson.ok(flag);
}
ResultJson是一个自定义的返回类型的包装类,你可以用别的类型
本文介绍了在数据库中实现假删除的方法,通过在表中添加一个`delete_flag`字段,用0和1表示数据是否被删除。在Mybatis中,使用update更新删除状态,详细讲述了在xml配置文件中如何进行集合遍历更新操作,并提到了mapper、service、service实现类和controller的实现流程。

758

被折叠的 条评论
为什么被折叠?



