SpringCloud Feign 傳遞複雜參數對象須要注意的地方

1.傳遞複雜參數對象須要用Post,另外須要注意,Feign不支持使用GetMapping 和PostMappingapp

@RequestMapping(value="user/save",method=RequestMethod.POST)

2.在傳遞的過程當中,複雜對象使用@RequestBody進行註解,同時接收端也須要使用@RequestBody這個註解。 博主遇一個坑:code

消費端使用了@RequestBody而服務端沒有接收@RequestBody,這時參數會接收不完整。對象

//消費端
	@RequestMapping(value="user/save",method=RequestMethod.POST)
	public User save(@RequestBody User user);

//服務端

@PostMapping("save")
	public User save(@RequestBody User user) {
		System.out.println(user);
		return UserService.save(user);
	}
相關文章
相關標籤/搜索