欢迎使用CSDN-markdown编辑器

来源:互联网 发布:js 双引号 编辑:程序博客网 时间:2024/06/05 17:26

工作中使用springmvc接口后台传入的json出现一些问题,好像前台的json字符串只能映射为java的对象,不能分割成为单个的字段接受

前台的代码

 function deleteProductOne(ids,name,isShow,brandId){            url= '${pageContext.request.contextPath }  /back/deleteProduct.do';       var json = {ids:ids,name:name,isShow:isShow,brandId:brandId};       json = JSON.stringify(json);      deleteOneAjax(json,url,"POST");}

如下的后台代码无法传参

@RequestMapping("/deleteProduct2.do")    public String deleteProduct(@RequestBody String ids,@RequestBody String name,@RequestBody Integer brandId,@RequestBody Integer isShow,Model model){        //将ids字符串转换为list        productService.deleteProduts(ids);          model.addAttribute("name", name);        model.addAttribute("brandId", brandId);        model.addAttribute("isShow", isShow);        return "redirect:/back/productList.do";    }

如下可以正确的传入

@RequestMapping("/deleteProduct2.do")    public String deleteProduct(@RequestBody String ids,@RequestBody String name,@RequestBody Integer brandId,@RequestBody Integer isShow,Model model){        //将ids字符串转换为list        productService.deleteProduts(ids);          model.addAttribute("name", name);        model.addAttribute("brandId", brandId);        model.addAttribute("isShow", isShow);        return "redirect:/back/productList.do";    }

QueryBean类

public class QueryBean{    private String ids;    private String name;    private int isDisplay;    private  Integer brandId;    private  Integer isShow;  省略setter和getter方法}
原创粉丝点击