Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
ldp-docs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
doc
ldp-docs
Commits
a1c117a0
Commit
a1c117a0
authored
Oct 30, 2020
by
马超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: 将feign使用样例写到文档中
parent
c2429d7d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
Example样例工程开发文档.md
开发文档/Example样例工程开发文档.md
+48
-0
No files found.
开发文档/Example样例工程开发文档.md
View file @
a1c117a0
...
...
@@ -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**
只要不手动清空,缓存会一直存在。
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment