Spring Boot(二):Web 综合开发

详见:http://www.ityouknow.com/springboot/2016/02/03/spring-boot-web.html

Web 开发

Spring Boot Web 开发非常的简单,其中包括常用的 json 输出、filters、property、log 等

json 接口开发

在以前使用 Spring 开发项目,需要提供 json 接口时需要做哪些配置呢

添加 jackjson 等相关 jar 包
配置 Spring Controller 扫描
对接的方法添加 @ResponseBody

就这样我们会经常由于配置错误,导致406错误等等,Spring Boot 如何做呢,只需要类添加 @RestController 即可,默认类中的方法都会以 json 的格式返回

@RestController
public class HelloController {
    @RequestMapping("/getUser")
    public User getUser() {
        User user=new User();
        user.setUserName("小明");
        user.setPassWord("xxxx");
        return user;
    }
}

猜你喜欢

转载自www.cnblogs.com/lukelook/p/10571617.html
今日推荐