当前位置:网站首页>糊涂工具类(hutool)post请求设置body参数为json数据
糊涂工具类(hutool)post请求设置body参数为json数据
2022-07-06 18:06:00 【穆雄雄】
大家好,我是雄雄,欢迎关注微信公众号雄雄的小课堂
今天介绍一个案例,糊涂工具类(hutool)post请求设置body参数为json数据,刚开始写的总是报错,下面是正确的代码:
/** * 添加动作 * @param projectVo * @return */
@Override
public String addProjectV3(@RequestBody ProjectVoV3 projectVo) {
JSONObject jsonObjectResult = new JSONObject();
//请求接口地址
String url = TrainingSchemeConstant.addProjectV3;
try {
String body = HttpUtil.createPost(url)
.contentType("application/json")
.body(JSON.toJSONString(projectVo)).execute().body();
if (StringUtils.isBlank(body)) {
jsonObjectResult.putOpt("code", "500");
jsonObjectResult.putOpt("data", null);
jsonObjectResult.putOpt("msg", "操作失败");
return jsonObjectResult.toString();
}
JSONObject obj = JSONUtil.parseObj(body);
if (obj == null) {
jsonObjectResult.putOpt("code", "500");
jsonObjectResult.putOpt("data", null);
jsonObjectResult.putOpt("msg", "操作失败");
return jsonObjectResult.toString();
}
String code = obj.get("code").toString();
if ("200".equals(code)) {
jsonObjectResult.putOpt("code", "200");
jsonObjectResult.putOpt("data", obj.get("data"));
jsonObjectResult.putOpt("msg", "操作成功");
//标记有没有记录
//jsonObjectResult.putOpt("count", obj.getJSONArray("data").size());
return jsonObjectResult.toString();
}
} catch (Exception e) {
log.error("获取训练方案失败:", e);
e.printStackTrace();
}
return null;
}
重点是下面的这行代码:
String body = HttpUtil.createPost(url)
.contentType("application/json")
.body(JSON.toJSONString(projectVo)).execute().body();
```
边栏推荐
- JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
- Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
- 编译命令行终端 swift
- C language instance_ two
- 公钥\私人 ssh避password登陆
- 设置Wordpress伪静态连接(无宝塔)
- 机器学习:随机梯度下降(SGD)与梯度下降(GD)的区别与代码实现。
- C language - array
- Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
- DS-5/RVDS4.0变量初始化错误
猜你喜欢
系统休眠文件可以删除吗 系统休眠文件怎么删除
Comparison of picture beds of free white whoring
Make Jar, Not War
dvajs的基础介绍及使用
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
LeetCode:1175. Prime permutation
子网划分、构造超网 典型题
Yunna - work order management system and process, work order management specification
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
随机推荐
C语言实例_5
MySQL script batch queries all tables containing specified field types in the database
云呐|工单管理办法,如何开展工单管理
THREE.AxesHelper is not a constructor
What are the differences between Oracle Linux and CentOS?
[signal and system]
Case development of landlord fighting game
Neon Optimization: About Cross access and reverse cross access
7.6模拟赛总结
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
如何管理分布式团队?
黑马笔记---异常处理
HMM notes
DS-5/RVDS4.0变量初始化错误
js如何快速创建一个长度为 n 的数组
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
Body mass index program, entry to write dead applet project
405 method not allowed appears when the third party jumps to the website
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform