@PostMapping("/logicRemove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(dataFieldService.logicDeleteDataFieldByIds(ids)); }
这里的AjaxResult 和 toAjax()只是封装返回的数据,返回值还是1或者0。
public int logicDeleteDataFieldByIds(String ids) { //使用工具类把字符串转换为数组 String[] strings = Convert.toStrArray(ids); return dataFieldMapper.logicDeleteDataFieldByIds(strings); }
int logicDeleteDataSetByIds(String[] ids);
工具类Convert
public class Convert{
public static String[] toStrArray(String str){
return toStrArray(",", str);
}
public static String[] toStrArray(String split, String str){
return str.split(split);
}
}
然后在对应的*mapper.xml中编写:
<delete id="logicDeleteDataSetByIds" parameterType="String">
delete from data_set where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
最后:前端传来的数据需要是“1,2,3”这种格式即可;