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