ajax提交json数据并使用Springmvc接收实例

1.页面代码

$.ajax({ type: "POST", contentType: "application/json",//必须加 dataType: "json", url: "/dataAnalysis/selsPoverty", data:JSON.stringify({ 'year': year, 'bar': qhdm }), success: function (data) {}}



2.后台代码
【ajax提交json数据并使用Springmvc接收实例】
@RequestMapping(value = "https://www.it610.com/selsPoverty", method = RequestMethod.POST, produces = "text/html; charset=UTF-8") @ResponseBody public String selsPoverty( HttpSession session,@RequestBody Map data) { SysAdmin admin = (SysAdmin) session.getAttribute(Constant.LOGIN_SESSION); JSONObject json=new JSONObject(data); User user=new User(); user.setPageNum(0); user.setInsert_Date(json.getString("year")); //user.setInsert_Date(json.getString("year")); Listlist = userService.getList(user); String str="["; //前台所需的数据DATA String lables="["; if(list.size()!=0){ for (int i = 0; i 1)?(str.substring(0, str.length()-1)):str; lables=(lables.length()>1)?(lables.substring(0, lables.length()-1)):lables; str+="]"; lables+= "]"; }else{ return "2"; }JSONObject rejson=new JSONObject(); json.put("lab", lables); json.put("strs", str); return rejson.toJSONString(); }




    推荐阅读