这是一个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;
注解中属性代表该请求返回参数类型为json格式;
下面代码无非就是设置http请求header中的contentType格式,和设置请求体内容
PostMapping也是一个组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写。
produces属性详见 https://blog.csdn.net/a137268431/article/details/17252099
简单的看 这个方法不就是对请求头做的处理么
如果我们不指定一个HttpClient的话,会默认帮我们创建一个,如果我们程序调用比较频繁的话,为了提高性能,会考虑使用PoolingHttpClientConnectionManager来构建HttpClient