ibatis中动态查询返回字段返回用resultClass="java.util.HashMap" Java.sql.SQLException: 列名无效的问题

错误信息:

org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   

--- The error occurred in jndi:/localhost/studen/WEB-INF/app-config/query/sqlmap/Test.xml.  
--- The error occurred while applying a result map.  
--- Check the QueryReport_QueryBucketTest.SELECT_QUERYUBUCKETTESTDETAIL_CN-AutoResultMap.  
--- Check the result mapping for the 'LPV_CNT_1' property.  

--- Cause: Java.sql.SQLException: 列名无效


SQLMAP:

<select id="getWarningRecordListForXXFK" resultClass="java.util.HashMap" parameterClass="java.util.HashMap">
    SELECT * FROM $tableName$
    WHERE MR_BatchNo IN
    (
    <iterate property="requestList" conjunction=",">
        #requestList[].ApplyForID#
    </iterate>
    )
</select>

表名动态传参,获取的结果集也是以Map形式动态返回的

Map<String,Object> paramap = new HashMap<String, Object>();//查询的参数Map
paramap.put("tableName",standardType.getScorrespondTable());
paramap.put("requestList",requestList);
String sqlId=getEntityName()+".getWarningRecordListForJSHD";List lstResult=warningDao.getSqlMapClientTemplate().queryForList(sqlId, paramap);//查询出来的结果
for(int i=0;i<lstResult.size();i++) {
    Map result = (Map)lstResult.get(i);
    String cardNo=result.get("CardNo").toString();
}
通过这种方式去接收结果集


因为ibatis保留列名为第一次查询时候的列名,第二次查另外一张表的时候,这张表中并没有第一张表的 列,所以就会报列名不存在!!

ibatis可以设置一个参数remapResults="true",每次查询都重新更新列名。



感谢 seng3018 的分享,原文地址:http://blog.csdn.net/seng3018/article/details/7550186

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值