Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Spring 通过URL传递参数访问RestWebservice_Spring_Web Services_Rest_Url_Jersey - Fatal编程技术网

Spring 通过URL传递参数访问RestWebservice

Spring 通过URL传递参数访问RestWebservice,spring,web-services,rest,url,jersey,Spring,Web Services,Rest,Url,Jersey,我试图通过Jersey+Spring中的URL传递rest方法中所需的参数 这是我的服务课 @Path("/find") public class DownLoadService { @Autowired TransactionWork transactionDownload; @POST @Path("/bring") public Response GetFile(String uid) { String result = tran

我试图通过
Jersey+Spring
中的
URL
传递rest方法中所需的参数

这是我的服务课

@Path("/find")
public class DownLoadService {

    @Autowired
    TransactionWork transactionDownload;

    @POST
    @Path("/bring")
    public Response GetFile(String uid) {
        String result = transactionDownload.BringFile(uid);
        return Response.status(200).entity(result).build();
    }

}
我正在尝试通过URL访问

http://localhost:8080/ProjectName/rest/find/bring'parameter for method getFile??'
我不知道有没有可能

(我第一次使用这个可能是愚蠢的问题)


注意:我可以在servlet中轻松访问此服务,并且工作正常。

等待了很长时间后,我发现了这种方法

    @GET
    @Path("/bring/{withUID}")
    public Response GetFile(@PathParam("withUID") String uid) {
        String result = transactionDownload.BringFile(uid);
        return Response.status(200).entity(result).build();
    }
现在我可以通过这种方式访问该服务

http://localhost:8080/RESTfulExample/rest/my/bring/AB
                                                   ^
                                                   parameter I passed to method

准备好学习其他方法来做同样的事情。
我不知道这是否可能。
当你尝试它时会发生什么?405方法不允许。好的-这是因为GET没有在服务上实现,并且通过在浏览器中输入该url(我假设你就是这样访问它的)您执行GET请求是的,我可以访问没有参数的服务方法,但我希望通过URL传递参数。您所说的“更好的答案”是什么意思?尽管你的url部分很奇怪,但如果你进入restfull之路,这就是实现它的方法。@DirkLachowski是的,我在发布问题后发现了它,但在此之前我不知道如何实现它,我不知道,但可能还有其他方法实现同样的事情(我想),方法是可以的,但你真的应该重新考虑你的资源名称。使用RESTful接口的全部目的是为您的资源提供有意义的名称。为了继续您的代码示例,我假设您有某种事务资源。每个事务都由uuid标识,并且(除其他外?)有一个文件负载。因此,一个可能的url可以是
/transaction//filePayload
。如果您使用
GET
调用它,那么您就有了获取事务负载的自然语义。你可以在@DirkLachowski上读到,好的,从这个意义上说,是的,我同意,谢谢你的链接。