使用RestTemplate接收数据
2018-02-26 00:00
411 查看
使用RestTemplate的postForEntity方法,返回结果为ResponseEntity<T>
/** * 增加设备 * * @param deviceInfo * @return */ @RequestMapping(path = "/add", method = RequestMethod.POST) public ResponseResult addDevice(DeviceInfo deviceInfo) { super.checkLoginUserAuth();//权限验证相关方法 Map<String, Object> params = toParams(deviceInfo); LocalResponseResult responseResult = super.buildResponseResult(params); //构造返回结果 ResponseEntity<Map> response = this.restTemplate.postForEntity("/device", params, Map.class); if (response.getStatusCode() != HttpStatus.OK) { return responseResult.result(response.getStatusCode()); } return responseResult.result(HttpStatus.OK, response.getBody()); } /** * 将注册对象转化为参数Map * * @param deviceInfo * @return */ private Map<String, Object> toParams(DeviceInfo deviceInfo) { Map<String, Object> params = Maps.newLinkedHashMap(); params.put("uuid", UUID.randomUUID().toString()); params.put("depotId", deviceInfo.getDepotId()); params.put("deviceSerialNumber", deviceInfo.getDeviceSerialNumber()); String direction = null; if (deviceInfo.getDirection() == Direction.IN) { direction = "IN"; } else if (deviceInfo.getDirection() == Direction.OUT) { direction = "OUT"; } params.put("direction", direction); params.put("operatorId", deviceInfo.getOperatorId()); params.put("operatorName", deviceInfo.getOperatorName()); params.put("remark", deviceInfo.getRemark()); return params; }
相关文章推荐
- 使用RestTemplate post方式提交表单数据
- 使用RestTemplate发送multipart/form-data格式的数据
- 使用UDPClient发送和接收数据
- Java网络编程从入门到精通(13):使用Socket类接收和发送数据
- ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField(转)
- Java网络编程从入门到精通(13):使用Socket类接收和发送数据
- 使用UDP非连线式发送接收数据(聊天室模式)
- 如何使用jdbc template查询数据,而用ibatis组装结果?
- 我的WCF4 Rest Service及Entity Framework with POCO之旅(三)——用Entity Framework和POCO Template实现数据模型及存储
- 使用template扩展已有的DDX_Text函数,使扩展能够同时支持各种数据类型的一个例子
- 通过使用UART0实现接收的数据
- silverlight 数据模板 DataTemplate 使用 codebehind实现
- 使用next()和nextLine()方法接收从键盘输入字符串型数据区别
- 使用Msp430的串口中断接收一包数据
- 使用UDP协议发送和接收数据
- 使用UDP协议发送和接收数据
- 接收XML数据并使用XSL样式表进行格式化
- 让JRTPLIB 发送/接收数据时使用同一个端口
- WPF中如何使用C#创建DataTemplate数据模版
- [翻译]Scott Mitchell 的ASP.NET 2.0数据教程之十三:在DetailsView控件中使用TemplateField