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

来源:互联网 发布:手机淘宝如何管理店铺 编辑:程序博客网 时间:2024/04/30 19:14

错误信息:

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>();//查询的参数Mapparamap.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

0 0
原创粉丝点击