jdbcTemplate的取值方法和注意事件

时间:2020-12-02 22:34:21

有一次测试,SQL里面的t.xx,在JAVA中要写成XX,要不然,取不出来

注意事件:

如果SQL里面写的是trim(t.name), 那在取出来的时候也要memberInfo.setMemberName(map.get("trim(t.name)")


String sql = "select trim(t.name), trim(t.idnumber), trim(t.mobile), " +

"trim(t.email), trim(t.insureaera), trim(t1.recipientadress) " +
"from T33_CARINSURANCE_CARINFO t, T33_CARINSURANCE_PEOPLESEND t1," +
" T33_CARINSURANCE_ORDER t2 where t1.orderid = t2.orderid and t2.carnumber = t.carnumber and t2.owner_id = t.idnumber and t2.orderid = '" + order.getOrderid() + "'";


try{ 
rl = jt.queryForList(sql);//搜索得到结果
System.out.println(rl.size());
if(rl.size()!=0){//结果不为空的情况
for(int i=0;i<rl.size();i++){//遍历结果
System.out.println("记录条数 :" + rl.size());
Map map=(Map)rl.get(i);//结果List中每一行为一个LinkedHashMap
  
if (map.get("trim(t.name)") != null)
memberInfo.setMemberName(map.get("trim(t.name)")
.toString().trim());
else
memberInfo.setMemberName("为空");
// System.out.println("memberInfo.getMemberName() :" + memberInfo.getMemberName());
// System.out.println("用户姓名 :" + map.get("trim(t.name)").toString());

if (map.get("trim(t.idnumber)") != null)
memberInfo.setIdCard(map.get("trim(t.idnumber)")
.toString().trim());
else
memberInfo.setIdCard("为空");

if (map.get("trim(t.mobile)") != null)
memberInfo.setMobileNo(map.get("trim(t.mobile)")
.toString().trim());
else
memberInfo.setMobileNo("为空");

if (map.get("trim(t.email)") != null)
memberInfo.setEmail(map.get("trim(t.email)")
.toString().trim());
else
memberInfo.setEmail("为空");

if (map.get("trim(t.insureaera)") != null)
memberInfo.setXzqhDM(map.get("trim(t.insureaera)")
.toString().trim());
else
memberInfo.setXzqhDM("为空");

if (map.get("trim(t1.recipientadress)") != null)
memberInfo.setAddrDetail(map.get("trim(t1.recipientadress)")
.toString().trim()); 
else
memberInfo.setAddrDetail("为空");
}
}
}
catch(Exception e){
e.printStackTrace();//捕获异常并打印
return false;
}