Spring Boot的JSON和HTML控制器

Spring Boot的JSON和HTML控制器,第1张

Spring Boot的JSON和HTML控制器

这是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-
使用视图



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5651362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存