赞
踩
在启动类中注入容器
在有@service注解类中,自动装载
- String url = "http://localhost:9083/api/update/"
-
- public String updataPerson(PersonModel personModel) {
- ObjectMapper objectMapper = new ObjectMapper();
- //设置头部
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
- String personString = null;
- try {
- personString = objectMapper.writeValueAsString(personModel);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- HttpEntity<String> requestEntity = new HttpEntity<>(personString,headers);
- // ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,personString, String.class);
- ResponseEntity<String> responseEntity = restTemplate.postForEntity(url,requestEntity, String.class);
- System.out.println(responseEntity.getBody());
- return responseEntity.getBody();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。