Commit a1c117a0 authored by 马超's avatar 马超

doc: 将feign使用样例写到文档中

parent c2429d7d
...@@ -658,6 +658,54 @@ public Pagination getUserListByRest() { ...@@ -658,6 +658,54 @@ public Pagination getUserListByRest() {
} }
``` ```
也可以直接使用Feign来做Rest请求,首先定义FeignClient,将服务名填写到注解中。通过注解描述出需要请求的接口地址、请求方式、参数以及返回值,省略掉发送请求和解析结果的实现。
```java
/**
* Feign请求mcs-service样例代码
* <p>
* 需要注解 @FeignClient并在注解中填上服务名
*
* @author machao
*/
@FeignClient("mcs-service")
public interface ExampleFeignService {
/**
* 通过Feign获取用户分页数据
* <p>
* 用注解写出请求地址/方法,以及参数和返回值
*
* @param index 页码
* @param size 每页数据数量
* @return 用户分页数据
*/
@RequestMapping(value = "/user/get/page", method = RequestMethod.GET)
RestResult<Pagination<LdpMcsUserInfo>> getUserPageByFeign(@RequestParam("pageIndex") int index, @RequestParam("pageSize") int size);
}
```
将服务注入到Rest层中,并调用接口拿到返回值
```java
@Autowired
ExampleFeignService exampleFeignService;
/**
* rest获取用户分页数据
*
* @return
*/
@GetMapping("/rest/feign/page")
public RestResult getPageByFeign() {
//直接调用在FeignClient定义的接口
return exampleFeignService.getUserPageByFeign(0, 10);
}
```
## 三、缓存使用 ## 三、缓存使用
在LDP中缓存分为两种,分别为**SessionCache****ApplicationCache**。在使用**SessionCache**之前,需要先通过**UAA**的登录,或者在请求头中携带有效的**X-Ldp-Token****PS:当前没有会话或者会话过期后,SessionCache就不可用**】,而**ApplicationCache**只要不手动清空,缓存会一直存在。 在LDP中缓存分为两种,分别为**SessionCache****ApplicationCache**。在使用**SessionCache**之前,需要先通过**UAA**的登录,或者在请求头中携带有效的**X-Ldp-Token****PS:当前没有会话或者会话过期后,SessionCache就不可用**】,而**ApplicationCache**只要不手动清空,缓存会一直存在。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment