spring boot 创建 restcontroller,返回json数据

参考:http://www.fengyunxiao.cn

 

1. 新建package和HelloController

 

2. 编写Rest风格的HelloController代码,@RestController注解的作用:代替@Controller和@ResponseBody两个注解。默认返回 json

@RestController
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping(value = "/sayHello", method = RequestMethod.GET)
    public String hello() {
        return "hello";
    }
}

 

3. 运行项目,打开浏览器查看:localhost:8080/hello/sayHello

 参考:http://www.fengyunxiao.cn

posted @ 2018-08-04 09:20  亦寒2017  阅读(570)  评论(1编辑  收藏  举报