Fork me on GitHub

Spring Boot 集成 RESTeasy

JAX-RS 是代表restful web service 的一套规范api,基于java,用来提供RESTful 风格的Web services 服务. JAX-RS 使用一系列注解来简化java开发. 规范常用注解

序号 注解 描述
1 @Path 类或者方法的相对地址,标注在类或者方法上
2 @GET HTTP GET请求用,用来获取资源
3 @PUT HTTP PUT 请求,用来创建资源
4 @POST HTTP POST 请求, 用来创建或者更新资源
5 @DELETE HTTP DELETE请求, 用来删除资源
6 @HEAD HTTP HEAD请求, 用来获取一个接口是否可用的状态
7 @Produces 返回数据的格式比如APPLICATION/XML, TEXT/HTML, APPLICATION/JSON
8 @Consumes 请求数据格式 , 如json
9 @PathParam 绑定url里面的参数
10 @QueryParam 绑定url后面的参数(?后面的)
11 @MatrixParam 绑定包含多个 property (属性)=value(值) 方法参数表达式
12 @HeaderParam 给header里面传参
13 @CookieParam 给cookie里面传参
14 @FormParam 给form传参
15 @DefaultValue 给参数一个默认值
16 @Context 可以注入HttpRequest,HttpResponse用

spring boot 集成 paypal 开源

1
2
3
4
5
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>2.3.0-RELEASE</version>
</dependency>

指定 servletMapping 路径 写一个类继承Application ,交给Spring 管理

1
2
3
4
@Component
@ApplicationPath("/v1/")
public class ApplicationPathImpl extends Application {
}

编写RESTful 接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Component
@Path("province/")
public class ExternalFacadeImpl implements ExternalFacade {
/**
* http://localhost:8080/v1/province/city/1
* @param id
* @return
*/
@Path("city/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Override
public Result<Boolean> getCity(@PathParam("id") Long id) { return new Result<>();
}
}
Thanks for the support