1
我想实现Spring REST方法。我试图获取和它的作品:Spring REST DELETE示例错误
@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;
}
}
然而,当我想实现删除它没有。我的方法是:
@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
<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 -x delete http://localhost:8080/ui/webapp/conf/1
第二个命令给出了错误:
curl: (7) couldn't connect to host
有一个在Tomcat的一侧没有错误,在调试时它不会进入删除方法主体。
任何想法?
,也许更重要的是: “用大写-X” ...... –
@Daniel Stenberg发明:你说得对,我已经改正/扩展答案 – Ralph