hutool依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.5</version>
</dependency>
fastjson解析json
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
post请求携带body
/**
* @MethodName problemWorkList
* @Description 查询问题信息列表
* @param pageNum 页码
* @param pageSize 条数
* @param problemWork 问题pojo
* @return com.hssmart.common.result.Result
*
* @Author syh
* @Date 2022/11/24 9:39
*/
@Override
public List<ProblemWork> problemWorkList(Integer pageNum, Integer pageSize, ProblemWork problemWork) {
// 封装body中json参数
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce("projectNo", "20221124-1665646812424");
System.out.println(JSONUtil.toJsonStr(jsonObject));
// 添加请求头信息
Map<String, String > heads = new HashMap<>();
// 使用json发送请求,下面的是必须的
heads.put("Content-Type", "application/json;charset=UTF-8");
/**
** headerMap是添加的请求头,
body是传入的参数,这里选择json,后端使用@RequestBody接收
*/
HttpResponse response = HttpRequest.post("http://localhost:8290/probledssdmwork/list/" + pageNum +"/" +pageSize)
.headerMap(heads, false)
.body(String.valueOf(jsonObject))
.timeout(5 * 60 * 1000)
.execute();
// 数据解析
com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(response.body());
String centre = JsonUtils.getString(jsonObject1, "data.list");
List<Object> list = com.alibaba.fastjson.JSONObject.parseArray(centre);
return JSON.parseArray(JSON.toJSONString(list), ProblemWork.class);
}