MyBatis if text=" condition=='1' " 如果condition为字符串报错NumberFormatExecption

本文解析了MyBatis在处理数字与字符串比较时的默认行为,并提供了解决方案,即将数字转换为字符串进行比较,以避免类型不匹配的问题。

是因为MyBatis会将1这类单个的数子,即使加上引号也会按照数字去比较,解决办法就是将1转为字符串 '1'.toString

<select id="getHeadBucketList" resultType="java.lang.String"> select distinct (to_char(l.plan_start_date, 'yyyy-MM-dd')) from t_aps_supply_require_line l inner join t_aps_supply_require_head t on l.head_id = t.id where t.plan_id = #{condition.planId,jdbcType=VARCHAR} <if test="condition.dataType != null and condition.dataType != ''"> and t.data_type = #{condition.dataType,jdbcType=VARCHAR} </if> <if test="condition.locationCodeArray != null and condition.locationCodeArray.length > 0"> and t.location_code = any(#{condition.locationCodeArray,jdbcType=VARCHAR}) </if> <if test="condition.deptCodeArray != null and condition.deptCodeArray.length > 0"> and t.dept_code = any(#{condition.deptCodeArray,jdbcType=VARCHAR}) </if> <if test="condition.deptNameArray != null and condition.deptNameArray.length > 0"> and t.dept_name = any(#{condition.deptNameArray,jdbcType=VARCHAR}) </if> <if test="condition.workSerctionArray != null and condition.workSerctionArray.length > 0"> and t.work_serction = any(#{condition.workSerctionArray,jdbcType=VARCHAR}) </if> <if test="condition.prodLineCnNameArray != null and condition.prodLineCnNameArray.length > 0"> and t.prod_line_cn_name = any(#{condition.prodLineCnNameArray,jdbcType=VARCHAR}) </if> <if test="condition.prodFamilyEnNameArray != null and condition.prodFamilyEnNameArray.length > 0"> and t.prod_family_en_name = any(#{condition.prodFamilyEnNameArray,jdbcType=VARCHAR}) </if> <if test="condition.prodModelCodeArray != null and condition.prodModelCodeArray.length > 0"> and t.prod_model_code = any(#{condition.prodModelCodeArray,jdbcType=VARCHAR}) </if> <if test="condition.itemCodeList != null and condition.itemCodeList.size > 0"> <choose> <when test="condition.itemCodeList.size ==1"> and t.item_code like <foreach collection="condition.itemCodeList" item="item"> '%'|| #{item} ||'%' </foreach> </when> <otherwise> and t.item_code in <foreach collection="condition.itemCodeList" item="item" separator="," open="(" close=")"> #{item} </foreach> </otherwise> </choose> </if> order by to_char(l.plan_start_date, 'yyyy-MM-dd') </select>解释
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值