@GetMapping("getJson")
public Result getJson(String id) {
System.out.println(DateUtil.formatTime(new Date()));
HashMap<String, Object> expertInfoQueryMap = new HashMap<>();
FileReader fileReader = new FileReader("G:\\BaiduNetdiskDownload\\医疗软件\\医疗代码\\02-尚医通后端代码\\yygh_parent\\service\\service_cmn\\src\\main\\java\\com\\atguigu\\yygh\\cmn\\controller" + "/testsql.json");
String result = fileReader.readString();
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(result);
Set<String> strings = jsonObject.keySet();
//针对读取的json文件进行强制转换
String ziudan = (String) jsonObject.get("ziudan");
String biaoming = (String) jsonObject.get("biaoming");
List<Map<String, Object>> date = (List<Map<String, Object>>) jsonObject.get("date");
Map<String, Object> map = date.get(0);
//获取map的所有key进行动态拼接
Set<String> keySet = map.keySet();
String ss="";
for (String s : keySet) {
ss+="#{map."+s+"},";
}
//截取指定的字符串,并进行拼接
String substring = ss.substring(0, ss.lastIndexOf(","));
String substring1= "("+substring+ ")";
System.out.println(substring1);
dictService.getJson(ziudan,biaoming,date,substring1);
// String dictName = dictService.getDictName("",value);
return Result.ok(expertInfoQueryMap);
}
<insert id="add3">
insert into ${biaoming}(${ziudan}) values
<foreach collection="date" item="map" separator=",">
${substring1}
</foreach>
</insert>
json文件结构 得加入糊涂工具类