Spring Cloud 微服务之间使用RestTemplate.postForEntity,服务端不的@RequestBody 不起作用?
作为客户端的微服务发送一个javaBean到服务端的微服务
客户端代码:
String ue_url = "http://localhost:8990/ue/add";
String jsonString = JSON.toJSONString(ueEngineeringData, SerializerFeature.PrettyFormat,
SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteDateUseDateFormat);
HttpEntity ue_entity = new HttpEntity(jsonString,headers);
//String jsonString = JSON.toJSONString(ueEngineeringData);
log.info("javaBean->json结果:" + ue_entity);
ResponseEntity<HashMap> ret = restTemplate_local.postForEntity(ue_url,ue_entity,HashMap.class);
调试结果:
2019-03-07 14:32:13.126 INFO 3020 --- [ Timer-0] c.p.n.task.EngineeringTimerTask : javaBean->json结果:<{
"id":0,
"latitudeXy":"20.0",
"longitudeXy":"20.0",
"ptEpc230UeCellLogicCellId":"",
"ptEpc230UeMacroEnbId":"",
"ueImsi":"34703030015800"
},{Content-Type=[application/json]}>
2019-03-07 14:32:13.131 INFO 3020 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
服务端的代码:
@RequestMapping(value = "/add",method = RequestMethod.POST)
@ResponseBody
public HashMap<String, Object> addUe(@RequestBody UeEngineeringData ue) {
log.info("Add UE");
log.info("ue.imis:"+ ue.getUeImis());
log.info("UeController-add-ue.Longitude"+ue.getLongitude());
log.info("UeController-add:" + ue.toString());
return ueEngineeringDataService.addUe(ue);
}
控制台输出:
2019-03-07 14:32:13.139 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : ue.imis:null
2019-03-07 14:32:13.139 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : UeController-add-ue.Longitudenull
2019-03-07 14:32:13.140 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : UeController-add:com.potevio.networkmonitoringdatabasecreatetables.domain.UeEngineeringData@4a2cd158
2019-03-07 14:32:13.140 INFO 3003 --- [io-8990-exec-10] c.p.n.service.UeEngineeringDataService : UeEngineeringData:imis:null
Hibernate: select ueengineer0_.id as id1_0_, ueengineer0_.latitude as latitude2_0_, ueengineer0_.longitude as longitud3_0_, ueengineer0_.pt_epc230ue_cell_logic_cell_id as pt_epc4_0_, ueengineer0_.pt_epc230ue_macro_enb_id as pt_epc5_0_, ueengineer0_.ue_imis as ue_imis6_0_ from ue_engineering_data ueengineer0_ where ueengineer0_.ue_imis is null
明明已经用阿里的fastJson转成Json发送过去了,为什么@RequestBody UeEngineeringData ue) 不起作用? 它里边的内容都是空的!
客户端代码:
String ue_url = "http://localhost:8990/ue/add";
String jsonString = JSON.toJSONString(ueEngineeringData, SerializerFeature.PrettyFormat,
SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteDateUseDateFormat);
HttpEntity ue_entity = new HttpEntity(jsonString,headers);
//String jsonString = JSON.toJSONString(ueEngineeringData);
log.info("javaBean->json结果:" + ue_entity);
ResponseEntity<HashMap> ret = restTemplate_local.postForEntity(ue_url,ue_entity,HashMap.class);
调试结果:
2019-03-07 14:32:13.126 INFO 3020 --- [ Timer-0] c.p.n.task.EngineeringTimerTask : javaBean->json结果:<{
"id":0,
"latitudeXy":"20.0",
"longitudeXy":"20.0",
"ptEpc230UeCellLogicCellId":"",
"ptEpc230UeMacroEnbId":"",
"ueImsi":"34703030015800"
},{Content-Type=[application/json]}>
2019-03-07 14:32:13.131 INFO 3020 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
服务端的代码:
@RequestMapping(value = "/add",method = RequestMethod.POST)
@ResponseBody
public HashMap<String, Object> addUe(@RequestBody UeEngineeringData ue) {
log.info("Add UE");
log.info("ue.imis:"+ ue.getUeImis());
log.info("UeController-add-ue.Longitude"+ue.getLongitude());
log.info("UeController-add:" + ue.toString());
return ueEngineeringDataService.addUe(ue);
}
控制台输出:
2019-03-07 14:32:13.139 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : ue.imis:null
2019-03-07 14:32:13.139 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : UeController-add-ue.Longitudenull
2019-03-07 14:32:13.140 INFO 3003 --- [io-8990-exec-10] c.p.n.controller.UeController : UeController-add:com.potevio.networkmonitoringdatabasecreatetables.domain.UeEngineeringData@4a2cd158
2019-03-07 14:32:13.140 INFO 3003 --- [io-8990-exec-10] c.p.n.service.UeEngineeringDataService : UeEngineeringData:imis:null
Hibernate: select ueengineer0_.id as id1_0_, ueengineer0_.latitude as latitude2_0_, ueengineer0_.longitude as longitud3_0_, ueengineer0_.pt_epc230ue_cell_logic_cell_id as pt_epc4_0_, ueengineer0_.pt_epc230ue_macro_enb_id as pt_epc5_0_, ueengineer0_.ue_imis as ue_imis6_0_ from ue_engineering_data ueengineer0_ where ueengineer0_.ue_imis is null
明明已经用阿里的fastJson转成Json发送过去了,为什么@RequestBody UeEngineeringData ue) 不起作用? 它里边的内容都是空的!
...全文
相关推荐
Spring Cloud多个微服务之间调用代码实例
主要介绍了Spring Cloud多个微服务之间调用代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
spring cloud eureka微服务之间的调用详解
主要介绍了spring cloud eureka微服务之间的调用详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Spring cloud restTemplate 传递复杂参数的方式(多个对象)
主要介绍了Spring cloud restTemplate 传递复杂参数的方式(多个对象),需要的朋友可以参考下
《深入理解Spring Cloud与微服务构建》学习笔记(十一)~使用RestTemplate和Ribbo消费服务
《深入理解Spring Cloud与微服务构建》学习笔记(十一)~使用RestTemplate和Ribbo消费服务
spring cloud中微服务之间的调用以及eureka的自我保护机制详解
主要介绍了spring cloud中微服务之间的调用以及eureka的自我保护机制详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧


其他
