0
我试图创建我的第一个Spring应用程序,它是一个简单的REST web服务。 我想使每个响应都是JSON(在标题中),我不知道如何在一次完成它,我的意思是不是在我所有的控制器方法中,比如配置文件或其他东西。第一个REST Spring应用程序
这是我的代码:
@RestController
public class HomeController {
@RequestMapping(value = "/something/{nom}/{id}", method = RequestMethod.GET)
public User hi(@PathVariable long id, @PathVariable String nom) {
return new User(id, nom);
}
}
感谢提前
尝试在'@ RestController'后添加'@ ResponseBody'。 – 2014-11-24 15:49:27
你有没有试过对此进行访问?默认情况下,用户应该由杰克逊解析为JSON字符串。 – Jaskey 2014-11-24 15:57:54
@KeithEnlow那不会帮助; '@ RestController'已经自动暗示'@ ResponseBody',没有必要明确地添加它。 – Jesper 2014-11-24 19:51:02