今天发现@RestController注解返回的默认格式成了xml,现在还没有找到原因,使用如下可以如常的返回json格式:
@RestController public class UserController { @Autowired private UserDao userDao; @GetMapping(value = "/{id}", produces = { "application/json;charset=UTF-8" }) public User findById(@PathVariable Long id) throws Exception { if (null == id) { return null; } User user = userDao.findById(id); return user; } }
xml格式可以试试:
@GetMapping(value = "/getUserBaseInfo", produces = { "application/xml;charset=UTF-8" })
本文出自 “我爱大金子” 博客,请务必保留此出处http://1754966750.blog.51cto.com/7455444/1956970
原文地址:http://1754966750.blog.51cto.com/7455444/1956970