RestEasy+用户指南----第5章.@PathParam

本文详细介绍了@PathParam注解在RESTful API中的应用,包括基本使用方法、正则表达式的高级配置及PathSegment的使用场景。

转载说明出处:http://blog.youkuaiyun.com/nndtdx/article/details/6870391

原文地址 http://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/index.html

只是分享,如有侵权,麻烦联系我删除,谢谢。

 

@PathParam 的声明允许你在URI路径中去映射你的方法将使用的参数。

(很简单,当你发出get请求 /book/152-963参数152-963就在isbn中存储着,然后交给变量id,这样你的方法就算是成功的接收了该参数)

这将允许你在uri中内嵌一个变量标识符。在上边的例子中,参数isbn被用来传递book的信息。你所嵌入的数据类型可以是任何元数据类型,例如String,具有String参数的构造函

数的一个类对象,或者a static valueOf method that takes a String as a parameter。例如,假设ISBN是一个对象,我们可以

或者是一个public方法String构造,包含一个valueOf 方法

(运行中应该能够自动调用类的valueOf方法进行转换,对Java不是很熟悉,我想大概应该是这样)

 

 

5.1. @PathParam深入 以及正则表达式

 

 

下边是一些更复杂的应用,这些在前边的章节并没有讨论

你可以指定一个或者多个参数用以内嵌到你的uri中,下边是一些例子

 

1.@Path("/aaa{param}bbb")

2.@Path("/{name}-{zip}")

3.@Path("/foo{name}-{zip}bar")

 

那么,路径 "/aaa111bbb" 将会匹配#1. "/bill-02115"将会匹配 #2. 路径"foobill-02115bar" 将会匹配 #3.

之前,我们已经讨论过如何在@Path中使用正则表达式

在如下的请求中,我们可以了解到“param”以及“many”值是多少

 

5.2@PathParam 和 PathSegment

Thespecification has a very simple abstraction for examining a fragment of the URIpath being invoked on javax.ws.rs.core.PathSegment:

你可以使用resteasy注入一个PathSegment而不是用一个值

当你使用matrix parameters传递诸多参数时,浙江爱那个非常有用。你可以将任意个name和value的键值对潜入到uri path segment中。PathSegment对象将会负责去获取这些参数。

你也可以看一下MatrixParam(后边会讲到)

一个matrix parameter的例子是

 

GEThttp://host.com/library/book;name=EJB 3.0;author=Bill Burke

 

Thebasic idea of matrix parameters is that it represents resources that areaddressable by their attributes as well as their raw id.

(好吧,5.2我表示不怎么理解,自己还没有试过这个部分。)

转载于:https://www.cnblogs.com/yzw23333/p/7234086.html

2025-05-27 17:29:45.743 ERROR 15325 --- [nio-8810-exec-4] [] [] org.jboss.resteasy.resteasy_jaxrs.i18n : RESTEASY002010: Failed to execute javax.ws.rs.NotSupportedException: RESTEASY003200: Could not find message body reader for type: class com.spotter.dtg.aetherflow.admin.adapter.web.request.liteChain.LiteUpdateFlowReq of content type: text/plain;charset=UTF-8 at org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound(ServerReaderInterceptorContext.java:53) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:80) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:198) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:91) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:113) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:543) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:432) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:393) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:395) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:364) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:337) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:440) [resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229) [resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135) [resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138) [resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215) [resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:245) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:61) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) ~[resteasy-jaxrs-3.12.1.Final.jar:3.12.1.Final]
最新发布
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值