Spring REST DELETE 示例错误
我想实现 Spring REST 方法。我尝试了 Get 并且它有效:
@RequestMapping(value = "{systemId}", method = RequestMethod.GET)
public
@ResponseBody
Configuration getConfigurationInJSON(HttpServletResponse response, @PathVariable long systemId) throws IOException {
if (configurationMap.containsKey(systemId)) {
return configurationMap.get(systemId);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return null;
}
}
但是当我想实现 DELETE 时它却不起作用。我的方法是:
@RequestMapping(value = "{systemId}", method = RequestMethod.DELETE)
public void deleteConfiguration(HttpServletResponse response, @PathVariable long systemId) throws IOException {
if (configurationMap.containsKey(systemId)) {
configurationMap.remove(systemId);
response.setStatus(HttpServletResponse.SC_FOUND);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
我的web.xml如下:
MVC 调度程序 org.springframework.web.servlet.DispatcherServlet 1
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/ui/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当我尝试使用 Curl 进行 GET 时有效的命令:
curl http://localhost:8080/ui/webapp/conf/1
当我尝试使用 Curl 进行 DELETE 时不起作用的命令:
curl -x delete http://localhost:8080/ui/webapp/conf/1
第二个命令在一段时间后在 curl 处给出该错误:
curl: (7) couldn't connect to host
Tomcat 端没有错误,并且在调试时没有错误t 输入删除方法主体。
有什么想法吗?
I want to implement Spring REST methods. I tried Get and it works:
@RequestMapping(value = "{systemId}", method = RequestMethod.GET)
public
@ResponseBody
Configuration getConfigurationInJSON(HttpServletResponse response, @PathVariable long systemId) throws IOException {
if (configurationMap.containsKey(systemId)) {
return configurationMap.get(systemId);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return null;
}
}
However when I want to implement DELETE it doesn't. My method is that:
@RequestMapping(value = "{systemId}", method = RequestMethod.DELETE)
public void deleteConfiguration(HttpServletResponse response, @PathVariable long systemId) throws IOException {
if (configurationMap.containsKey(systemId)) {
configurationMap.remove(systemId);
response.setStatus(HttpServletResponse.SC_FOUND);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
My web.xml as follows:
mvc-dispatcher
org.springframework.web.servlet.DispatcherServlet
1
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/ui/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Command that works when I try with Curl for GET:
curl http://localhost:8080/ui/webapp/conf/1
Command that doesn't work when I try with Curl for DELETE:
curl -x delete http://localhost:8080/ui/webapp/conf/1
Second command gives that error after a time later at curl:
curl: (7) couldn't connect to host
There is no error at Tomcat side and at debug it doesn't enter the delete method body.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
使用大写
DELETE
和大写X
Try
with uppercase
DELETE
and uppercaseX