Spring boot 微服务之间@RequestMapping("method = RequestMethod.POST")或者@PostMapping取不到值

微服务A中的serivce类(有@FeignClient注解的):

  @RequestMapping(value = "/Activity/saveActivity", method = RequestMethod.POST)
  JsonResult saveActivity(Activity activity);

微服务B中的Controller

 @RequestMapping(value = "/saveActivity", method = RequestMethod.POST)
    public JsonResult saveActivity(@RequestBody Activity activity){
        return cmsActivityService.saveActivity(activity);
    }

解决方法:

1.如果是对象,在参数中添加@RequestBody注解

2.如果是单个或者多个参数,则在Service中的方法参数加上@RequestParam("id"),Controller也加上这个

举个栗子比如根据ID查询,我自己也记一下

Service(有FeignClient注解那个类)

//根据ID查询
@GetMapping("/cmsActivity/gettivityById")
JsonResult gettivityById(@RequestParam("id") String id);

Controller

 @GetMapping("/cmsActivity/getActivityById")
    public JsonResult getActivityById(@RequestParam("id") String id){
        return ActivityService.getById(id);
    }

 

你可能感兴趣的:(问题收获)