Controller
服务端controller实现获取用户列表的功能,函数接收pageable的queryparam,返回带分页的用户列表。
@GetMapping
fun list(pageable: Pageable): Mono<Page<User>> = mono { userService.list(pageable) }
Feign client
如果直接用一下方式进行调用,Controller能接收到请求,但是无法正常解析pageable参数,因为feign生成的请求地址有误http://service/apis/v1/users?pageable=Page request [number: 0, size 10]
,因此格式不对,无法解析。
@GetMapping(consumes = ["application/json"])
fun list(@RequestParam pageable: Pageable): Page<User>
解决
把Pageable转为Map<String, Any>
即可,使用map进行传递。
@GetMapping(consumes = ["application/json"])
fun list(@RequestParam pageable: Map<String, Any): Page<User>
[1] Reference
其他
当我传递两个Map作为参数,报以下错误
FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Query map can only be present once.
只能合并两个Map成一个进行传递。
网友评论