SpringCloud使用feign传递参数问题

1.传递非对象参数

接口、FeignClient

@FeignClient(value = "micro-user-5030")
public interface UserService {

    @RequestMapping("user/getUserById")
    public User selectUserByPrimaryKey(@RequestParam("id") Integer id);

    @RequestMapping("user/getUserByName")
    public User selectUserByName(@RequestParam("name") String name);

    
}

消费者 

@PostMapping("/setUserState")
@ResponseBody
public String setUserState(@RequestParam("id") String id){
      //something
}

2.传递对象参数

接口、FeignClient 

@FeignClient(value = "micro-user-5030")
public interface UserService {

    @RequestMapping("user/updateUser")
    public boolean updateUser(@RequestBody User user);

}

消费者 

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/user/add")
    public Stirng addUser(@RequestBody User user){
        userService.addUser(user);
        return "success";
    }
}

 

你可能感兴趣的:(Java,springcloud)