表结构字段名称与json key名称一致:
package com.ruoyi.doris; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import java.io.File; import java.nio.charset.Charset; import java.util.UUID; @Slf4j public class PurReqLineTest { public static void main(String[] args) throws Exception { // be String host = "192.168.0.132"; // be接口 int port = 8030; String database = "br"; String table = "PurchaseRequestLines"; String user = "root"; String passwd = "xxx"; // String s = "[{\"longitude\": \"19\", \"city\": \"北京\", \"latitude\": \"39.916927\"},{\"longitude\": \"2010\", \"city\": \"北京\", \"latitude\": \"39.916927\"}]"; String s = FileUtil.readString(new File("D:\\采购需求.txt"), Charset.defaultCharset()); // System.out.println(s); JSONArray value = JSONObject.parseObject(s).getJSONArray("value"); log.info("size {}", value.size()); for(int i=0;i<value.size(); i++){ JSONArray linesArray = value.getJSONObject(i).getJSONArray("DocumentLines"); for(int j=0; j<linesArray.size(); j++) { JSONObject lineObj = linesArray.getJSONObject(j); log.info("{}",lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString()); lineObj.put("LineEntryId", lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString()); linesArray.set(j, lineObj); String label = getUUID(); HttpResponse response = HttpRequest.put("http://" + host + ":" + port + "/api/" + database + "/" + table + "/_stream_load") .basicAuth(user, passwd) .header("Expect", "100-continue") .header("label", label) .header("Content-Type", "text/plain; charset=UTF-8") .header("format", "json") // 导入json数组 // .header("strip_outer_array", "true") .body(lineObj.toString()).setFollowRedirects(true) .execute(); log.info(response.body()); // Thread.sleep(3*1000); } } } public static String getUUID() { String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); return uuid; } }
表结构字段名称与json key不一致
package com.ruoyi.doris; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import java.io.File; import java.nio.charset.Charset; import java.util.UUID; @Slf4j public class PurReqLineTest { public static void main(String[] args) throws Exception { // be String host = "192.168.0.132"; // be接口 int port = 8030; String database = "br"; String table = "PurchaseRequestLines"; String user = "root"; String passwd = "xxxx"; // String s = "[{\"longitude\": \"19\", \"city\": \"北京\", \"latitude\": \"39.916927\"},{\"longitude\": \"2010\", \"city\": \"北京\", \"latitude\": \"39.916927\"}]"; String s = FileUtil.readString(new File("D:\\采购需求.txt"), Charset.defaultCharset()); // System.out.println(s); JSONArray value = JSONObject.parseObject(s).getJSONArray("value"); log.info("size {}", value.size()); for(int i=0;i<value.size(); i++){ JSONArray linesArray = value.getJSONObject(i).getJSONArray("DocumentLines"); for(int j=0; j<linesArray.size(); j++) { JSONObject lineObj = linesArray.getJSONObject(j); log.info("{}",lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString()); lineObj.put("LineEntryId", lineObj.getInteger("DocEntry").toString() + lineObj.getInteger("LineNum").toString()); linesArray.set(j, lineObj); String label = getUUID(); HttpResponse response = HttpRequest.put("http://" + host + ":" + port + "/api/" + database + "/" + table + "/_stream_load") .basicAuth(user, passwd) .header("Expect", "100-continue") .header("label", label) .header("Content-Type", "text/plain; charset=UTF-8") .header("format", "json") // 导入json数组 // .header("strip_outer_array", "true") .body(lineObj.toString()).setFollowRedirects(true) .execute(); log.info(response.body()); // Thread.sleep(3*1000); } } } public static String getUUID() { String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); return uuid; } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2020-09-09 Oracle、MySql、SQLServer 数据分页查询(转)