springmvc ajax jackson
如下处理的好处为:
1.不用因为查询而另外定义bean(新增,修改:做bean的映射比较好)
2.415的处理为修改ajaxcontentType:'applition/json',默认传递方式会报不支持
$.ajax({
url:'...',
data: {data:JSON.stringify(param)},
dataType: 'json',
success : function(results){
if(results.result) {
alert('totalSize : '+ results.totalSize);
// _reFreshTable(results);
}
}
})@RequestMapping(value="/query")
public @ResponseBody ObjectNode queryInfo(HttpServletRequest request) {
String data = request.getParameter("data");
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
JsonNode jsonNode = null;
try {
jsonNode = mapper.readValue(data, JsonNode.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//do some query
//deal the result
JsonNode node = jsonNode;
if (node != null) {
System.out.println("extCustOrderId : "+node.path("extCustOrderId").getTextValue());
}
// Map<String, Object> returnMap = new HashMap<String, Object>();
ObjectNode rootObj = mapper.createObjectNode();
ObjectNode termInfoBackList = mapper.createObjectNode();
termInfoBackList.put("test", "good");
rootObj.put("result", "true");
rootObj.put("totalSize", "22");
rootObj.put("termInfoBackList", termInfoBackList);
return rootObj;
} 相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
时光如瑾雨微凉 2020-07-19
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05