这是Spring Boot的默认行为。唯一的是,您必须标记其中之一
@RequestMapping才能生成JSON。例:
@Controllerclass HelloController { // call http://<host>/hello.json @RequestMapping(value = "/hello", method = RequestMethod.GET, produces = "application/json") @ResponseBody public MyObject helloRest() { return new MyObject("hello world"); } // call http://<host>/hello.html or just http://<host>/hello @RequestMapping(value = "/hello", method = RequestMethod.GET) public String helloHtml(Model model) { model.addAttribute("myObject", new MyObject("helloWorld")); return "myView"; }}
有关更多信息,请访问:http : //spring.io/blog/2013/05/11/content-negotiation-using-spring-
mvc和http://spring.io/blog/2013/06/03/content-negotiation-
使用视图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)