关于ibatis出现AutoResultMap错误的问题

近日开发中用到ibatis在使用的过程中出现了AutoResultMap的错误

配置如下:

<select id="statistic" parameterClass="map" resultClass="java.util.HashMap">
    select 
	<isNotNull  property="category">
        b.description as descriptionB,
    </isNotNull>
	<isNotNull  property="serl">
        c.description as descriptionC,
    </isNotNull>
	sum(1) as total
	from 
		t_es_reginfo a
		<isNotNull  property="category">
			<isEqual compareValue="city" property="category">
				left join t_bs_$category$ b 
					on a.$category$=b.code
			</isEqual>
			<isNotEqual compareValue="city" property="category">
				left join t_cd_$category$ b 
					on a.$category$=b.id
			</isNotEqual>
		</isNotNull>
		<isNotNull  property="serl">
			<isEqual compareValue="city" property="serl">
				left join t_bs_$serl$ c 
					on a.$serl$=c.code
			</isEqual>
			<isNotEqual compareValue="city" property="serl">
				left join t_cd_$serl$ c 
					on a.$serl$=c.id
			</isNotEqual>
		</isNotNull>
	where a.examid=#examid#
	<isNotNull property="city">
		and a.city=#city#
	</isNotNull>
	group by 1
	<isNotNull property="category">
        ,a.$category$
    </isNotNull>
	<isNotNull property="serl">
	   ,a.$serl$
	</isNotNull>
	order by -1
	<isNotNull property="category">
        ,a.$category$
    </isNotNull>
	<isNotNull property="serl">
	    ,a.$serl$
	</isNotNull>
  </select>

 由于多次产生的列数可能会不一样,所以当每一次查出来是三列,第二次是两列的话就会报AutoResultMap的错( java.sql.SQLException:   列名无效),经查后发现有个remapResults的属性可以设置为true就可以了,原因如下:

 

在 【statement】, 【select】, 和【procedure】 标签中存在一个可选的属性【remapResults 】,默认值是false.如果每次查询的列不定的话,这个属性需要设置为true. 为了避免经常的对返回的结果进行内省,iBATIS 会记录上一次查询结果的元数据, iBATIS 会在每次查询的时候内省查询结果来设置元数据,来保证返回恰当的结果。这个属性会造成一定的性能损失,所以要谨慎使用,只在你需要的时候使用--查询列发生变化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值