没找到用sql解析数组列的语句,最后用java实现。
代码和postman如下:
java代码:
public static void parseArray(String param) throws UnsupportedEncodingException {
String url= params.get("body").replaceAll("%(?![0-9a-fA-F]{2})", "%25"); //转码(遇到(%)转译)
param = URLDecoder.decode(url, "utf-8").trim();
JSONObject json=JSONObject.fromObject(param);
String dataName = json.getString("tableName");
String where = json.getString("where");
BatchService batchService = (BatchService)MyBeanFactory.getService("batchService");
JSONObject DBJson=json.getJSONObject("DBJson");
String field1="orderId";
String field2="rep";
List<JSONObject> findtPayment = batchService.findtPayment(dataName, where, DBJson);
List<TDApplyVO> TDApplyVOLists=new ArrayList<>();
for(JSONObject jParam:findtPayment){
String jsonObject1= jParam.getString(field1);
TDApplyVO tdApplyVO = new TDApplyVO();
tdApplyVO.setOrderId(jsonObject1);
if (jParam.get(field2)!=null) {
final JSONArray jsonObject2= jParam.getJSONArray(field2);
for (int i = 0; i < jsonObject2.size(); i++) {
JSONObject temp1=(JSONObject) jsonObject2.get(i);
String string=temp1.getString("item_id");
if (temp1.getString("item_id").equals("1253232")) {
JSONObject temp2=(JSONObject) temp1.get("item_detail");
tdApplyVO.setSevenApply(temp2.getString("platform_count"));
}else if (temp1.getString("item_id").equals("1253234")) {
JSONObject temp2=(JSONObject) temp1.get("item_detail");
tdApplyVO.setOneMouthApply(temp2.getString("platform_count"));
}else if(temp1.getString("item_id").equals("1253236")){
JSONObject temp2=(JSONObject) temp1.get("item_detail");
tdApplyVO.setThreeMouthApply(temp2.getString("platform_count"));
}
}
}
TDApplyVOLists.add(tdApplyVO);
}
System.out.println(TDApplyVOLists.size());
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter("./test/temp.txt"));
for (TDApplyVO tdApplyVO : TDApplyVOLists) {
writer.write(tdApplyVO.toString() + "\r\n");
}
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
postman:
{"tableName":"temp0221","field":"","where":"","DBJson":{"url":"jdbc:mysql://127.0.0.1:3306/dataBase?characterEncoding=UTF-8" ,"username":"root","password":"root"}}