【发布时间】:2018-06-08 02:57:54
【问题描述】:
我正在使用 MyEclipse 生成带有 REST 服务的 CRUD 应用程序,Web CRUD 应用程序生成良好并且工作正常,但我也想使用 REST 服务,生成的 RestControler 是这样的:
@Controller("NewsRestController")
public class NewsRestController {
/**
* DAO injected by Spring that manages News entities
*
*/
@Autowired
private NewsDAO newsDAO;
/**
* Service injected by Spring that provides CRUD operations for News entities
*
*/
@Autowired
private NewsService newsService;
/**
* Create a new News entity
*
*/
@RequestMapping(value = "/News", method = RequestMethod.POST)
@ResponseBody
public News newNews(@RequestBody News news) {
newsService.saveNews(news);
return newsDAO.findNewsByPrimaryKey(news.getId());
}
/**
* Show all News entities
*
*/
@RequestMapping(value = "/News", method = RequestMethod.GET)
@ResponseBody
public List<News> listNewss() {
return new java.util.ArrayList<News>(newsService.loadNewss());
}
我尝试使用此 url 调用此服务:
http://localhost:8080/JPO/NewsRestController/News
我使用 Postman 来测试这个 REST 服务,我没有得到任何响应。 可能是什么问题?
【问题讨论】:
-
我试过了,但没有用
-
在postman中试试
http://localhost:8080/JPO//News,选择Get方法,你最好声明一个新的get映射路径。 -
我收到 HTTP 406 错误,这与 Accept 标头有关
-
我不得不添加杰克逊罐子,现在它正在工作,谢谢你们的帮助
标签: java spring rest web-services myeclipse