SSM框架------删除多条数据
程序员文章站
2024-03-19 19:13:44
...
对于初学mybatis的同学来说,在后台删除多条数据是一个比较棘手的事情,在这里分享一下自己操作过的后台删除数据
Controller层
@RequestMapping(value = "/delMore", method = RequestMethod.POST,headers = "Accept=application/json")
public QueryDada delMore(@RequestBody Integer [] list) throws Exception {
QueryDada queryDada = new QueryDada();
try {
userServiceImpl.delMore(list);
queryDada.setCode(Constans.SUCCESS_CODE);
queryDada.setMessage(Constans.QUERY_USER_MESSAGE);
} catch (Exception e) {
e.printStackTrace();
queryDada.setCode(Constans.QUERY_USER_ERROR_MESSAGE);
queryDada.setMessage(Constans.QUERY_USER_ERROR_MESSAGE);
}
return queryDada;
}
service层
public void delMore(Integer [] list) {
userDao.delMore(list);
}
dao/mapper层
void delMore(Integer [] list);
mapper.xml
<delete id="delMore" parameterType="java.util.Arrays">
delete from user
where id in
<foreach collection="array" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
postman端
queryData类
public class QueryDada {
private String code;
private Object data;
private String Message;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getMessage() {
return Message;
}
public void setMessage(String message) {
Message = message;
}
}
上一篇: UVa1585