Feign 客户端–服务端传递参数为空
框架:springcloud
技术:feign
请求发送工具:postman
问题:在客户端传递的参数不为空,但是在服务端却只能接收到null数据
客户端controller代码:
@Autowired
private MerchantClient merchantClient;
@RequestMapping(value = "/merchant/insertMerchant", method = RequestMethod.POST)
public int insertMerchant(TMerchant tMerchant){
return merchantClient.insertMerchant(tMerchant);
}
客户端client接口代码:
@FeignClient(name = "sys-provider",fallback = MerchantFallBack.class)
public interface MerchantClient {
/**
* 新增商户信息
* @param tMerchant 商户信息
*/
@RequestMapping(value = "/merchant/insertMerchant", method = RequestMethod.POST,consumes = "application/json")
int insertMerchant(@RequestBody TMerchant tMerchant);
}
服务端controller代码:
@Autowired
private MerchantService merchantService;
@RequestMapping(value = "insertMerchant", method = RequestMethod.POST)
public int insertMerchant(TMerchant tMerchant){
return merchantService.insertMerchant(tMerchant);
}
解决:feign两端传递参数不匹配,在客户端使用@RequestBody但在服务端不使用@RequestBody,两端参数不对等
更改服务端controller代码:
@Autowired
private MerchantService merchantService;
@RequestMapping(value = "insertMerchant", method = RequestMethod.POST)
public int insertMerchant(@RequestBody TMerchant tMerchant){
return merchantService.insertMerchant(tMerchant);
}