标签:style http java color os io
public class JsonView { public static ModelAndView Render(Object model, HttpServletResponse response) { MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter(); MediaType jsonMimeType = MediaType.APPLICATION_JSON; try { jsonConverter.write(model, jsonMimeType, new ServletServerHttpResponse(response)); } catch (HttpMessageNotWritableException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }
这是实现方法,下边是调用方法:
@RequestMapping(value="/users", method=RequestMethod.POST)public Object index(@RequestBody SearchUsersViewModel model, HttpServletResponse response) { model.setList(userService.getUsers(model)); if(true) { return new ModelAndView("controls/tables/users", "model", model); } else { return JsonView.Render(model, response); } }
spring mvc 返回字符串或者是view的方法,布布扣,bubuko.com
标签:style http java color os io
原文地址:http://my.oschina.net/closeday/blog/290024