spring rest @PathParam

阅读数:80 评论数:0

跳转到新版页面

分类

python/Java

正文

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

@Path("/library")
public class Library {
 
   @GET
   @Path("/book/{isbn}")
   public String getBook(@PathParam("isbn") String id) {
      // search my database and get a string representation and return it
   }
}

使用类对象

   @GET
   @Path("/book/{isbn}")
   public String getBook(@PathParam("isbn") ISBN id) {...}
 
 
   public class ISBN {
      // 要有一个具有String参数的构造函数
      public ISBN(String str) {...}
   }
或者
public class ISBN {
     //包含一个valueOf方法
     public static ISBN valueOf(String isbn) {...}
  }

在@Path中使用正则表达式

@GET
@Path("/aaa{param:b+}/{many:.*}/stuff")
public StringgetIt(@PathParam("param") String bs, @PathParam("many")String many) {...}

 

Request

param

many

GET /aaabb/some/stuff

bb

some

GET /aaab/a/lot/of/stuff

b

a/lot/of




相关推荐

(1)Spring MVC是一个基于DispatcherServlet的MVC框架,DispatcherServlet是继承自HttpServlet的。Spring的IOC和AOP主要就用了java的

如果一个类交张spring管理,比如 &lt;bean id="foo1" class="demo.scope.foo" /&gt; 不指明scope就是单例。</p

方式1:通过@PostConstruct和@PreDestroy方法。 从Java EE5开始,Servlet增加了两个影响Servlet生命周期的注解。 方式2:通

一、概述 1、spring容器 spring中有三种bean容器:BeanFactory、ApplicationContext、WebApplicationContext。 (1)BeanFactor

有时我们在做开发的时候需要记录每个任务执行时间,或者记录一段代码执行时间,最简单的方法就是打印当前时间与执行完时间的差值,然后这样如果执行大量测试的话就很麻烦,并且不直观,如果想对执行的时间做进

一、request uri部分 @PathVariable 获取路径参数,形如url/{id} 二、request header部分 @RequestHeade

一、概述 springboot中有两种方式使用kafka时,直接使用kafka-client连接kafka服务;另一种是使用spring-kafka框架来连接kafka。 1、版本兼容 使用时要注意版

当然可以自己写redis的工具类,或者使用第三方开源jar包或代码,这里使用spring boot的集成类。 一、pom依赖 <dependency> <gro

websocket协议基于tcp的网络协议,它实现浏览器与器全双工通信。 spring boot2 +websocket 1、添加依赖 <pre clas

一、概述 druid是阿里开源的数据库连接池。 二、springboot集成druid 1、方式一 <dependency> <groupId>com.alibaba</grou