传统SSM项目调用SpringCloud微服务方法

1.返回值是自定义实体类,参数是基本类型

User user= restTemplate.getForObject(
                "http://localhost:8081/user/getById/{id}",
                User.class, id);

2.返回值是List<基本类型>,参数是基本类型

List<String> list = restTemplate.getForObject(
                "http://localhost:8081/user/nameList/{page}/{pageSize}",
                List.class, "1", "4");

3.返回值是List<自定义pojo>,参数基本类型

ResponseEntity<List<User>> responseEntity = restTemplate.exchange(
                "http://localhost:8086/user/userList/{page}/{pageSize}",
                HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>(){},
                "1", "4");
List<User> list = responseEntity.getBody();

4.返回值是自定义pojo,参数是自定义pojo

User user = new User();
ResponseEntity entity = restTemplate.postForObject(
                "http://localhost:8081/user/add/",
                user, ResponseEntity .class);

5.返回值是自定义pojo,参数是enum和基本类型

ResponseEntity entity = restTemplate.postForObject(
                "http://localhost:8081/user/updateState/{id}",
                StateFlagEnum.delete, ResponseEntity .class, "100");

你可能感兴趣的:(java)