ajax 传对象数组到后台

来源:互联网 发布:求一些莆田鞋的淘宝店 编辑:程序博客网 时间:2024/05/19 13:29

前台 :

var jsonMarker =JSON.stringify(newMarkers)$.ajax({type: "post",  url:"saveMapMaker",data:jsonMarker,contentType: "application/json; charset=utf-8",                    dataType: "json", success:function(date){alert(date.msg);}});

后台

@ResponseBody@RequestMapping(value = "saveMapMaker", method = RequestMethod.POST ) public AjaxDto saveMarker( @RequestBody String marker ) throws JsonParseException, JsonMappingException, IOException{  ObjectMapper objectMapper = new ObjectMapper();        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, TMapMaker.class);       List<TMapMaker> list = objectMapper.readValue(marker, javaType);            mapService.saveAll(list);      AjaxDto a =new AjaxDto(); a.setMsg("success");return a;}


原创粉丝点击