spring boot 接受ajax数组

来源:互联网 发布:linux系统漏洞修复 编辑:程序博客网 时间:2024/05/20 19:19

最近在用spring boot + vue.js作后台,在做批量删除的时候出现了异常

jackson报的错

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.lang.String[] out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String[] out of START_OBJECT token
 at [Source: java.io.PushbackInputStream@72bf7f09; line: 1, column: 1]

转换成fastjson报的错

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: exepct '[', but {, pos 1, json : {"systemIds":["1201678f34e24bf087a33efb88ca1d64 ","0e90bc00e6914c51bd0dfee01c97b55a "]}; nested exception is com.alibaba.fastjson.JSONException: exepct '[', but {, pos 1, json : {"systemIds":["1201678f34e24bf087a33efb88ca1d64 ","0e90bc00e6914c51bd0dfee01c97b55a "]}




好吧,看不懂,果断把spring boot原生的jackjson换成咱们中国的fastjson,好了,这下看懂了。原来是我前台发送的参数不对。json转换需要最外层就是数组的[],我的参数在内层才是数组。




const url = self.HOST + "/system/delete";self.$axios.post(url,{systemIds:ids}).then((response) => {    if(response.data.code == '100'){        self.$message.success('批量删除成功');    }else{        self.$message.error(response.data.mesg);    }})


把参数换成这样就对了

好吧,看不懂,果断把spring boot原生的jackjson换成咱们中国的fastjson,好了,这下看懂了。原来是我前台发送的参数不对。



const url = self.HOST + "/system/delete";self.$axios.post(url,ids).then((response) => {    if(response.data.code == '100'){        self.$message.success('批量删除成功');    }else{        self.$message.error(response.data.mesg);    }})

好吧,看不懂,果断把spring boot原生的jackjson换成咱们中国的fastjson,好了,这下看懂了。原来是我前台发送的参数不对。


原创粉丝点击