当前位置:网站首页>Feign calls get and post records
Feign calls get and post records
2022-07-28 02:23:00 【RT_ 0114】
feign Call points get and post most , Other put and delete No explanation
1、get request
The caller passes userId and size And bind the @RequestParam, The service provider will automatically resolve to userId To User Object's UserId On , analysis size To PageRequest Object's size On .
service provider :
Parameter description :@PathVariable("organizationId") Long tenantId The service provider and the service caller are consistent User user The caller does not need to pass entities , The attributes of the teleportation body can be, for example userIdPageRequest pageRequest The caller does not need to pass entities , The attributes of the teleportation body can be, for example size
@ApiOperation(" Inquire about ")
@GetMapping("/v1/{organizationId}/page")
public ResponseEntity<Page<User>> page(@PathVariable("organizationId") Long tenantId, User user, PageRequest pageRequest) {
Page<User> page = PageHelper.doPageAndSort(pageRequest, () -> service.page(user));
return Results.success(page);
}
Service callers :
Parameter description :@PathVariable("organizationId") Long tenantId The service provider and the service caller are consistent @RequestParam("userId") Long userId Is the second parameter of the service provider User An attribute of must use @RequestParam Binding property name @RequestParam("size") int size Is the third parameter of the service provider pageRequest An attribute of must use @RequestParam Binding property name
feign Interface
@FeignClient(
value = "service",
fallbackFactory = RemoteServiceFallbackFactoryImpl.class,
path = "/v1/"
)
public interface RemoteService {
@GetMapping("{organizationId}/page")
ResponseEntity<Page<User>> page(@PathVariable("organizationId") Long tenantId,
@RequestParam("userId") Long userId,
@RequestParam("size") int size);
}
feign abnormal
@Slf4j
@Component
public class RemoteServiceFallbackFactoryImpl implements RemoteService{
@Override
public ResponseEntity<Page<User>> page(Long tenantId, Long userId, int size) {
log.info(" Failed to get data , Call parameters :{},{}", userId, size);
throw new CommonException(" Acquisition failure ");
}
}
controller call
@Slf4j
@RestController()
@RequestMapping({
"/v1/{organizationId}"})
public class TestController extends BaseController {
@Autowired
PrmRemoteService remoteService;
@GetMapping(value = "/smy-test")
public ResponseEntity<?> smyTest() {
int size = 999;
ResponseEntity<Page<PrLine>> page= remoteService.page(0L, 1L, size);
return Results.success(page);
}
}
2、post request
service provider :
Parameter description :@PathVariable("organizationId") Long tenantId The service provider and the service caller are consistent @RequestBody User user The service provider and the service caller are consistent PageRequest pageRequest The caller does not need to pass entities , The attributes of the teleportation body can be, for example size
@PostMapping({
"/v1/{organizationId}/create"})
public ResponseEntity<Page<User>> create(@PathVariable("organizationId") Long tenantId,@RequestBody User user,PageRequest pageRequest) {
Page<User> page = lineService.create(tenantId, user, pageRequest);
return Results.success(page);
}
Service callers :
feign Interface :@PathVariable("organizationId") Long tenantId The service provider and the service caller are consistent @RequestBody User user The service provider and the service caller are consistent PageRequest pageRequest Is the third parameter of the service provider pageRequest An attribute of must use @RequestParam Binding property name
@FeignClient(
value = "service",
fallbackFactory = RemoteServiceFallbackFactoryImpl.class,
path = "/v1/"
)
public interface RemoteService {
@PostMapping("/{organizationId}/create")
ResponseEntity<Page<PrLine>> create(@PathVariable("organizationId") Long tenantId,
@RequestBody User user,
@RequestParam("size") int size);
}
feign abnormal
@Slf4j
@Component
public class RemoteServiceFallbackFactoryImpl implements RemoteService{
@Override
public ResponseEntity<Page<User>> page(Long tenantId, User user, int size) {
log.info(" The data of failure , Call parameters :{},{}", userId, size);
throw new CommonException(" Line failed ");
}
}
controller call
@Slf4j
@RestController()
@RequestMapping({
"/v1/{organizationId}"})
public class TestController extends BaseController {
@Autowired
PrmRemoteService remoteService;
@GetMapping(value = "/smy-test1")
public ResponseEntity<?> smyTest1() {
int size = 999;
User user= new User();
user.setUserId(888L);
ResponseEntity<Page<PrLine>> page= prmRemoteService.create(21L,user,size);
return Results.success(page);
}
}
summary :
get The formal parameters of the request caller must be annotated , The service provider is the object receiving , The caller must use @RequestParam modification , Write more than one .
post The request caller must have a @RequestBody Annotations are passed to objects and can only have one , If there are other objects to receive @RequestParam modification , Write more than one .
边栏推荐
- LeetCode 热题 HOT 100 -> 1.两数之和
- go 学习02 基础知识
- 一文读懂Plato&nbsp;Farm的ePLATO,以及其高溢价缘由
- Software test interview question: please introduce the meaning of various test types in detail?
- Use of classes in typescript
- 使用BigDecimal类型应该避免哪些问题?(荣耀典藏版)
- Flex布局学习完成PC端
- Eredi reappeared at the digital China Summit and continued to deepen the protection of green waters and mountains with science and technology
- 【愚公系列】2022年07月 Tabby集成终端的使用
- 并发编程的三大核心问题(荣耀典藏版)
猜你喜欢

Two ways for wechat applet to realize dynamic horizontal step bar

CeresDAO:Ventures DAO的“新代言”

Codeworks round 810 (Div. 2) a~c problem solution

CeresDAO:全球首个基于DAO赋能Web3.0的去中心化数字资产管理协议

Ceresdao: the world's first decentralized digital asset management protocol based on Dao enabled Web3.0

Traversal and properties of binary trees

学会这招再也不怕手误让代码崩掉

小程序毕设作品之微信校园浴室预约小程序毕业设计成品(2)小程序功能

go 学习01

How to evaluate the effectiveness of R & D personnel? Software Engineer reports help you see everyone's contribution
随机推荐
Zkrollup learning materials summary
新零售业态下,零售电商RPA助力重塑增长
Principle and implementation of cross entropy
Day6 函数和模块的使用
Skywalking distributed system application performance monitoring tool - medium
【ROS进阶篇】第十讲 基于Gazebo的URDF集成仿真流程及实例
[Yugong series] July 2022 go teaching course 019 - for circular structure
[advanced ROS chapter] Lecture 10 gadf integrated simulation process and examples based on gazebo
[advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control
SkyWalking分布式系统应用程序性能监控工具-中
Product interpretation - Design and distributed expansion of metersphere UI test module
Eredi reappeared at the digital China Summit and continued to deepen the protection of green waters and mountains with science and technology
Flex布局—固定定位+流式布局—主轴对齐—侧轴对齐—伸缩比
[机缘参悟-53]:阳谋立身,阴谋防身
Codeworks round 807 (Div. 2) a-c problem solution
Common problem types and methods of mathematical univariate differential proof problems in postgraduate entrance examination
Promise从入门到精通 (第1章 Promise的介绍和基本使用)
Software test interview question: please introduce the meaning of various test types in detail?
IT这个岗位,人才缺口百万,薪资水涨船高,上不封顶
LeetCode 热题 HOT 100 -> 1.两数之和