首页 > 其他 > 详细

关于INTEGER 类型在Mybatis中使用if的注意

时间:2016-03-30 18:05:16      阅读:317      评论:0      收藏:0      [点我收藏+]

Mybatis中是使用<if>用来编写动态语句是很方便的一个操作,不过在最近的项目开发中当使用的一个变量为inteter类型的时候,用<if>来编写发现有点问题,源码如下面:

<update id="updateWeightintervalInfo" parameterType="com.exiao.platform.core.logistics.data.WeightInterval">
		update tm_weightinterval SET
		<if test="wgtintervalCode!=null and wgtintervalCode !=‘‘">
			wgtintervalcode=#{wgtintervalCode},
		</if>
		<if test="intervalName!=null and intervalName!=‘‘">
			intervalname=#{intervalName},
		</if>
		<if test="transportMode!=null and transportMode!=‘‘">
			transportmode=#{transportMode},
		</if>
		<if test="vendorCode !=null and vendorCode !=‘‘">
			vendorcode=#{vendorCode},
		</if>
		<if test="departurecityCode!=null and departurecityCode!=‘‘">
			departurecitycode=#{departurecityCode},
		</if>
		<if test="minWeight !=null and minWeight !=‘‘">
			minweight=#{minWeight},
		</if>
		<if test="maxWeight != null and maxWeight !=‘‘">
			maxweight=#{maxWeight},
		</if>
		<if test="firstWeight !=null and firstWeight !=‘‘">
			firstweight=#{firstWeight},
		</if>
		<if test="addedWeight != null and addedWeight!=‘‘">
			addedweight=#{addedWeight},
		</if>
		<if test="sortSeq!=null and sortSeq!=‘‘">
			sortseq=#{sortSeq},
		</if>
		<if test="enabled!=null and enabled!=‘‘">
			enabled=#{enabled},
		</if>
		update_time=#{updateTime},
		updator=#{updator}
		WHERE wgtintervalid=#{id}
	</update>

其中enabled是interger类型,其中用0表示无效,1表示有效。如果传值为0的时候,按照if的逻辑则不判断为false不执行当中的语句。经过查找资料,只需要把代码中的enabled!=‘’去掉则可以正常使用。

关于INTEGER 类型在Mybatis中使用if的注意

原文:http://hhc1986.blog.51cto.com/10764456/1758489

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!