Mybatis报There is no getter for property named 'orgCode' in 'class java.lang.String'

本文介绍了在MyBatis的mapper.xml文件中如何正确处理单参数为String类型的情况,尤其是在SQL语句中进行条件判断时的注意事项。文章通过对比错误与正确的代码示例,解释了为何需要将参数替换为_parameter,并提供了Oracle数据库中判断字段是否为空的正确语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  在mapper.xml中 , 如果单参数是String类型 , 且在sql语句中对参数进行了判断 , 如下 when 中的判断 , 如果出现 if 判断也是一样的。都需要把判断中的参数用 _parameter 来代替 ,。

  另外orcal中判断字段是否为空需要使用 is null , 同理,判断不为空使用 is not null 。

  错误查询:

<select id = "select"  resultMap="ResultMap" parameterType="String">
     select
         name,code,parent,level
    from
         table
    <where>
        <choose>
            <when test="code != null and code !=''">
                    and code = #{code}
            </when>
            <otherwise>
                    and code is null
            </otherwise>
        </choose>
    </where>
</select>

  正确查询:


<select id = "select"  resultMap="ResultMap" parameterType="String">
     select
         name,code,parent,level
    from
         table
    <where>
        <choose>
            <when test="_parameter !=null and _parameter !=''">
                    and code = #{code}
            </when>
            <otherwise>
                    and code is null
            </otherwise>
        </choose>
    </where>
</select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值