spring3 controller 使用json format返回数据
实现标题这个议题,首先我们需要加入2个包,
<dependency> <groupId>org.codehaus.jackson</groupId><artifactId>jackson-core-asl</artifactId><version>1.5.6</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-asl</artifactId><version>1.5.6</version></dependency>
@RequestMapping(value="/content-type/{prodId}")@ResponseBodypublic Map<String,List<ContentType>> listContentTypeByProdJSONFormat(HttpServletRequest request,@PathVariable("prodId") int prodId){List<ContentType> contentTypeList = contentTypeService.listContentTypeByProduct(prodId);Map<String,List<ContentType>> contentTypes = new HashMap<String,List<ContentType>>();contentTypes.put("contentTypes", contentTypeList);return contentTypes;}success:function(data){var typeList = data.contentTypes;var length = typeList.length;............});