问题描述:传入参数为数据库表明或者sql语句时,返回HashMap无法获取动态的字段显示
例如: <select id="searchPageInfo" resultClass="java.util.HashMap" parameterClass="java.lang.String" remapResults="true">
$sqlStr$
</select>
解决方法: 在 select 中加入一个属性值: remapResults="true"
***************************************************************************************************************************
官方说明:
节选(iBatis-sqlMaps-2)文档参考
Map类型的Result
Result Map也可以方便为一个Map(如HashMap或TreeMap)对象赋值。使用下面讨论的API(参见 executeQueryForList()),还可以得到Map对象的集合(即Map的List)。Map对象与Java Bean同样的方式映射,只是使用name属性值作为Map的键值,用它来索引相应的数据库字段值,而不是象Java Bean一样给属性赋值。例如,如果您要将Product对象的数据装入Map,可以这样做:
<resultMap id=”get-product-result” class=”java.util.HashMap”>
<result property=”id” column=”PRD_ID”/>
<result property=”code” column=”PRD_CODE”/>
<result property=”description” column=”PRD_DESCRIPTION”/>
<result property=”suggestedPrice” column=”PRD_SUGGESTED_PRICE”/>
</resultMap> http://www.ibatis.com Clinton Begin 著 刘涛(toleu@21cn.com) 译
开发指南 iBATIS SQL Maps Page 32 of 62
上面的例子会创建一个HashMap的实例并用Product的数据赋值。Property的name属性值(即“id”)作为HashMap的键值,而列值则作为HashMap中相应的值。
当然,可以把Map类型Result和隐式的Result Map一起使用。例如:
<statement id=”getProductCount” resultClass=”java.util.HashMap”>
select * from PRODUCT
</statement>
* 官方没有说明动态传入Sql时返回 HashMap 会遇到的问题
***************************************************************************************************************************
关于Ibatis 中 sqlMap 返回 HashMap 时的问题
最新推荐文章于 2019-11-07 11:45:27 发布