你好杰米 2018-03-28 04:05 采纳率: 90%
浏览 653
已采纳

[Java]请问springMVC这段代码啥意思,关于httpclient的

这是一个controller方法的尾巴,方法上的返回值是void
请问这个注解中的属性和下面那段代码表示的什么意思
“JsonParam”和“cfg.getJsonParam()”表示的是项目里的一个属性类,不用在意

 @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
  public void upload(。。。。。。。。
 HttpHeaders headers = new HttpHeaders();
      MediaType mediaType = new MediaType("application", "merge-patch+json");
      headers.setContentType(mediaType);

      HttpEntity<JsonParam> entity = new HttpEntity<>(cfg.getJsonParam(), headers);
      HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
      RestTemplate restTemplate = new RestTemplate(requestFactory);

为了看的方便我把包放出来

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
  • 写回答

3条回答 默认 最新

  • yerikdiao 2018-03-28 05:06
    关注

    注解中属性代表该请求返回参数类型为json格式;
    下面代码无非就是设置http请求header中的contentType格式,和设置请求体内容

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?