前端传递数组批量删除

今天做关于批量删除的操作,之前都是拼接字符串然后到后台转换,感觉有点麻烦,于是试了直接传递数组到后端,做个笔记方便之后回顾。

传递数组对象前端用Ajax实现,具体代码如下:

var checkedArr = [];

......

$.ajax({
				type : 'POST',
				url: "settings/dictionary/deleteDic.do",
				data : {'arrays[]':checkedArr},
				dataType:"json",
				success : function(data) {
					if (data.code==1){
						alert("删除成功");
						window.location.href="settings/dictionary/selectDictionary.do";
					} else{
						alert("删除失败");
					}

				},

后台接收:

@RequestMapping(value="/settings/dictionary/deleteDic.do",method = { RequestMethod.POST})
    @ResponseBody
    public Object deleteDic( @RequestParam(value = "arrays[]", required = false)String[] arrays){ 
        Map<String,Object> map = new HashMap<>();

        int i =tblDicTypeService.deleteByPrimaryKey(arrays);
        
...

xml:

<delete id="deleteByPrimaryKey"  parameterType="java.util.Arrays" >
    delete from tbl_dic_type where code in
        <foreach collection="array" open="(" close=")" separator="," item="code">
          #{ code}
        </foreach>

  </delete>
    原文作者:渴望暴富的菜鸡程序员
    原文地址: https://blog.csdn.net/qq_45337977/article/details/107010455
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞