Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SpringWS中使用相同的URL获取和发布_Java_Spring_Web Services - Fatal编程技术网

Java 如何在SpringWS中使用相同的URL获取和发布

Java 如何在SpringWS中使用相同的URL获取和发布,java,spring,web-services,Java,Spring,Web Services,我希望坚持API最佳实践,因此希望使用相同的URL来获取和更新资源。我的GET实现类似于: @RequestMapping(value = "/userconfig/{userName}", method = (RequestMethod.GET)) @ResponseBody public String userPreferenceService(@PathVariable String userName) { 这个很好用。 当我尝试实现更新方法时,如: @RequestMapp

我希望坚持API最佳实践,因此希望使用相同的URL来获取和更新资源。我的GET实现类似于:

@RequestMapping(value = "/userconfig/{userName}", 
     method = (RequestMethod.GET))
@ResponseBody
public String userPreferenceService(@PathVariable String userName) {
这个很好用。 当我尝试实现更新方法时,如:

@RequestMapping(value = "/userconfig/{userName}", 
    method = RequestMethod.PUT)
public String userPreferenceUpdateService(@PathVariable String userName,
        @RequestBody UserPreference userPreference) {
这两种方法我都得到了404分。我记得几年前遇到过类似的问题,当时我使用Spring实现web服务,但忘记了我当时做错了什么。
任何指点都很好

如M.Deinum所述;这与SpringMVC有关。我曾经遇到过这样的需求,我所做的就是从.jsp文件中添加一个隐藏字段,该字段更改了方法名称,如下所示:

<form id="deleteForm" action="your/url/" method="post">
  <input type="hidden" name="_method" value="PUT" />
</form>


这就解决了我的问题。有关这方面的更多信息,请参阅《实践中的春天》(Spring in Practice),作者是威利·惠勒(Willie Wheeler),作者是约书亚·怀特(Joshua White),我读过这本书,他们经常使用这种解决方案。

我点击了错误的URL:/你想要什么
RequestMethod.PUT
RequestMethod.POST
?分享你想要的URL尝试点击时,需要了解呼叫是否正确。我觉得很好,我相信您在客户端有问题。这与Spring WS无关。这只是一个Spring MVC Rest控制器。请重新措辞你的问题。