1、jdbc request中SQL不能以“ ; ”结尾
2、获取数据库查询结果字段,字段名称必须为大写
3、查询获取到数据库表中的日期字段,需转换为String类型,才能打印出日期格式,不然打印出来是时间戳
4、获取数据库结果集,处理数据为json,作为接口口传参
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.text.*;
List orderInfo = vars.getObject("orderInfo");
List orderItemInfo = vars.getObject("orderItemInfo");
JSONObject jsonObject = new JSONObject();//构建json
JSONObject odObject = new JSONObject();//订单
JSONArray oddArray = new JSONArray();//数组
if(orderInfo=="null"){
}
for(Object o: orderInfo){
Map map =(Map)o;
odObject.put("id",map.get("ID"));
odObject.put("createtime",map.get("CREATETIME").toString());
odObject.put("roomId",map.get("ROOM_ID"));
odObject.put("starttime",map.get("STARTTIME").toString());
odObject.put("endtime",map.get("ENDTIME").toString());
odObject.put("personNum",map.get("PERSON_NUM"));
odObject.put("orderSource",map.get("ORDER_SOURCE"));
odObject.put("orderStatus",map.get("ORDER_STATUS"));
odObject.put("updatetime","${__timeShift(yyyy-MM-dd HH:mm:ss,,,,)}','yyyy-mm-dd hh24:mi:ss");//获取当前时间
odObject.put("roomName",map.get("ROOM_NAME"));
jsonObject.put("htOrder",odObject);//将订单信息放入htOrder
log.info("ddfffdd"+":"+odObject.get("roomName"));
}
for(Object o:orderItemInfo){
JSONObject oddObject = new JSONObject();//订单明细
Map map =(Map)o;
oddObject.put("id",map.get("ID"));
oddObject.put("orderId",map.get("ORDER_ID"));
oddObject.put("mobile",map.get("MOBILE"));
oddObject.put("name","测试");//修改姓名
oddObject.put("detailStatus",map.get("DETAIL_STATUS"));
oddArray.add(oddObject);
//log.info("dddd"+":"+oddObject.get("name"));
}
jsonObject.put("htOrderDetails",oddArray);//将订单明细信息放入htOrderDetails
log.info(jsonObject.toJSONString());
vars.putObject("order",jsonObject);