spring cloud 学习过程中遇到的问题

在此,记录一下初学springcloud过程中遇到的问题:

1,consumer向provider请求过程中,出现参数丢失问题:2019-03-31

consumer方法:

1     @RequestMapping(value = "consumer/person/add", method = RequestMethod.GET)
2     public boolean addPerson(Person person) {
3 
4 //        return restTemplate.postForObject(URL_PROVIDER + "/add", person, Boolean.class);
5 
6         return restTemplate.getForObject(URL_PROVIDER + "/add", Boolean.class, person);
7     }

provider方法:

1     @RequestMapping(value = "add", method = RequestMethod.GET)
2     public boolean addPerson(Person person) {
3         return personService.addPerson(person);
4     }

 

 

 person类:

1     private Long id;
2     private String personName;
3     private String dbSource;

 

浏览器请求:

1 http://localhost:8080/consumer/person/add?personName=ub

 

 

结果 consumer方法中的person拿到了personName,但是provider中的person却是null。

假如把consumer以及相关的方法换成post,也不行:

consumer:

1 return restTemplate.postForObject(URL_PROVIDER+"/add", person, Boolean.class);

 

posted @ 2019-03-31 11:54  往事零落碾作尘  阅读(385)  评论(0编辑  收藏  举报