【发布时间】:2015-11-06 03:07:43
【问题描述】:
我正在使用 spring 构建一个 Restful API,当我访问以下方法时:
// get the entity in DB by using id number
@RequestMapping(value = "/{id:.+}", method = RequestMethod.GET)
public @ResponseBody
User getEmployee(@PathVariable("id") String email) {
User user=null;
System.out.println(email);
try {
user = dataServices.getEntityById(email);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(user.getNickname());
return user;
}
使用此网址:http://localhost:8080/RestCrud/user/richard_johnson@sina.com
收到 406 错误:
我确定我已经添加了
<mvc:annotation-driven />
我也确定我在 pom.xml 中添加了这些 jackson 依赖项
************************编辑****************************** ***********
************************再次编辑****************************** ******
如您所见,我没有在 @RequestMapping 注释中限制标头,因此我认为这不是与标头限制相关的问题。
另外,我的网址格式如下:
http://localhost:8080/RestCrud/user/id
我已经测试了“列表” http://localhost:8080/RestCrud/user/list
它可以工作,但“id”路径不起作用
【问题讨论】:
-
你有什么问题?
-
嗯,请求来自哪里?什么是请求接受标头?原因可能在那里......
-
我的问题是如何解决这个 406 ;)
-
嗨,谢尔盖我根据你的问题编辑了我的帖子
标签: java spring maven spring-mvc