当前位置:网站首页>解析JSON接口并批量插入到数据库中
解析JSON接口并批量插入到数据库中
2022-06-26 03:59:00 【躺着数星星】
接口为NBA接口json接口
使用hutool工具类在后端进行解析(防止跨域)
@GetMapping("/pachou")
public String teamMessage() {
s = HttpUtil.get("https://china.nba.cn/stats2/season/conferencestanding.json?");
return s;
}
获取前端传递的数据使用fastJSON进行解析并批量插入
@PostMapping("/addBatch")
public Result addBatch(@RequestBody String str) {
JSONArray jsonArray = JSONArray.parseArray(str);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject json = JSONObject.parseObject(jsonArray.get(i).toString());
String profile = json.getString("profile");
JSONObject jsons = JSONObject.parseObject(profile);
String city = jsons.getString("city");
String abbr = jsons.getString("abbr");
String cityEn = jsons.getString("cityEn");
String displayConference = jsons.getString("displayConference");
String displayAbbr = jsons.getString("displayAbbr");
String nameEn = jsons.getString("nameEn");
String division = jsons.getString("division");
Team team = new Team();
team.setAbbr( abbr);
team.setCityEn(cityEn);
team.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss"));
team.setDisplayConference(displayConference);
team.setDisplayAbbr(displayAbbr);
team.setNameEn(nameEn);
team.setDivision(division);
teamService.save(team);
}
return Result.success("成功");
}
前端vue发送请求
//发送数据
send: function () {
request.get("/team/pachou").then(res => {
console.log(res)
this.standingGroups = res.payload.standingGroups[1].teams
console.log(this.standingGroups)
// JSON.stringify(this.standingGroups)
/* this.standingGroups.forEach(e=>{ JSON.stringify(this.standingGroups) console.log(JSON.stringify(this.standingGroups)); })*/
request.post("/team/addBatch",this.standingGroups).then(res => {
console.log(res)
})
})
},

大功告成1
边栏推荐
- Can string be changed?
- 【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
- Open camera anomaly analysis (I)
- VHDL设计
- Matplotlib multi line chart, dot scatter chart
- Lua语法讲解
- Dix critères de base importants pour les essais de débogage de logiciels
- English version of ternary loss
- What preparation should I make before learning SCM?
- Sorting out the knowledge points of the renderview renderobject parentdata of the shuttle
猜你喜欢

Optimization - multi objective planning

Detailed explanation of globalkey of flutter

Can string be changed?

MapReduce execution principle record

Force buckle 515 Find the maximum value in each tree row

商城风格也可以很多变,DIY 了解一下

Dix critères de base importants pour les essais de débogage de logiciels

用eclipse连mysql数据库出错然后出现图中的话是咋回事呀

【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter

Chrome page recording and playback function
随机推荐
Getting started with flask
MapReduce execution principle record
In 2022, what professional competitions can college students majoring in automation, electrical engineering and automation participate in?
matplotlib多条折线图,点散图
What does virtualization mean? What technologies are included? What is the difference with private cloud?
神经网络学习小记录71——Tensorflow2 使用Google Colab进行深度学习
力扣 515. 在每个树行中找最大值
面了个字节拿25k出来的测试,算是真正见识到了基础的天花板
三元损失英文版
Judge the same value of two sets 𞓜 different values
Detailed explanation of widget construction process of fluent
使用SOAPUI访问对应的esb工程
R语言与机器学习
第 4 篇:绘制四边形
线程同步之互斥量(互斥锁)
MySQL advanced part (IV: locking mechanism and SQL optimization)
816. fuzzy coordinates
2021 year end summary
外包干了四年,人直接废了。。。
I/O 虚拟化技术 — VFIO