【发布时间】:2015-04-11 23:27:18
【问题描述】:
@RequestMapping(value = "/user/{username:.+}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
User user(@PathVariable String username) {
User user = userRepository.findByUsername(username);
if (user == null)
throw new UserNotFoundException("User not found");
return user;
}
这是表示该操作的方法。控制器用@RestController注解
已解决
内容类型协商机制应该被覆盖。
探索:http://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc
代码:
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.mediaType("pl", MediaType.APPLICATION_JSON);
}
【问题讨论】:
-
看看这个 [链接] (stackoverflow.com/questions/7462202/…)
标签: java spring spring-mvc spring-boot