1.POM里面引入HTTP相关jar包: <dependency> <groupId>org.a;/groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>org.a;/groupId> <artifactId>httpmime</artifactId> <version>4.5.6</version> </dependency> 2. 编写HttpUtil,代码如下: import com.alibaba.; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.re; import java.lang.re; import java.nio.c; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.a; import org.; import org.Factory; import org.; public class HttpUtil { private static final Logger log = LoggerFac); private static final RequestConfig requestConfig = Reque() .setSocketTimeout(30000) .setConnectTimeout(30000) .setConnectionRequestTimeout(30000) .build(); public static <T> JSONObject httpRequest(String httpUrl, T t) { JSONObject jsonObject = new JSONObject(); HttpResponse httpResponse = null; CloseableHttpClient httpClient = null; try { httpClient = H(); MultipartEntityBuilder multipartEntity = Mul().setMode); ContentType contentType = Con("text/plain", C("UTF-8")); Class<? extends Object> tClass = t.getClass(); Field[] fields = (); if (null != fields && > 0) { for (int i = 0; i < ; i++) { //设置可以访问私有变量 fields[i].setAccessible(true); //获取属性的名字 String fieldName = fields[i].getName(); //将属性名字的首字母大写 String firstChar = (0, 1); fieldName = (firstChar, ()); Method m = ("get" + fieldName); Object value = m.invoke(t); if (value != null) { String fieldTypeName = fields[i].getType().getName(); switch (fieldTypeName) { case "java.lang.Integer": mul(fieldName, value.toString()); break; case "java.lang.Long": mul(fieldName, value.toString()); break; case "java.lang.String": StringBody stringBody = new StringBody(), contentType); mul(fieldName, stringBody); break; case "java.io.File": FileBody fileBody = new FileBody((File) value); mul(fieldName, fileBody); break; case "org.": MultipartFile multipartFile = (MultipartFile) value; InputStream inputStream = mul(); String fileName = mul(); mul(fieldName, inputStream, Con, fileName); break; default: break; } } } } mul(C("UTF-8")); HttpEntity entity = mul(); HttpPost httpPost = new HttpPost(httpUrl); (requestConfig); (entity); //执行提交 httpResponse = (httpPost); int returnCode = ().getStatusCode(); if (returnCode == H) { HttpEntity httpEntity = (); byte[] json = En(httpEntity); String responseJson = new String(json, "UTF-8"); jsonObject = JSONObject.parseObject(responseJson); //关闭流 En(httpEntity); } } catch (Exception ex) { j("code", "500"); j("message", ex.getMessage()); log.error("upload file exception", ex); } finally { if (null != httpResponse) { try { ((CloseableHttpResponse) httpResponse).close(); } catch (IOException e) { e.printStackTrace(); } } if (null != httpClient) { try { (); } catch (IOException ex) { ex.printStackTrace(); } } } return jsonObject; } } 3.编写服务端代码: @RequestMapping("/batchImport") @ResponseBody public JSONObject batchImport(WorkerImport workerImport) { JSONObject jsonObject = new JSONObject(); // do someting return jsonObject; } 4.编写客户端调用代码: @RequestMapping("/batchImport") @ResponseBody public JSONObject upload(WorkerImport workerImport){ String url = ";; JSONObject jsonObject = H(url, workerImport); return jsonObject; }