String 参数 作为if 条件

Posted yangfei969

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了String 参数 作为if 条件相关的知识,希望对你有一定的参考价值。

mybatis mapper.xml sql  当parameterType为String时 任何参数都必须为_parameter(比如原先为参数为key),若果没有_parameter,提示错误There is no getter of  ‘username‘ in java.lang.string

int pagingCount(String key);

 

<select id="pagingCount" resultType="int" parameterType="string">
         SELECT 
            count(1)
        FROM 
            users 
        WHERE 1=1
        <if test="key != null and ‘‘ != key">
            name = #{key} or username = #{key}
        </if>
     </select>

 

<select id="pagingCount" resultType="int" parameterType="string">
         SELECT 
            count(1)
        FROM 
            users 
        WHERE 1=1
        <if test="_parameter != null and ‘‘ != _parameter">
            and name = #{_parameter} or username = #{_parameter}
        </if>
     </select>

 

以上是关于String 参数 作为if 条件的主要内容,如果未能解决你的问题,请参考以下文章

Mybatis if test 条件参数为0的一个坑

Mybatis -- 动态Sql概述动态Sql之<if>(包含<where>)动态Sql之<foreach>sql片段抽取

兼容ie8,firefox,chrome浏览器的代码片段

将条件作为参数传递给 OpenCL 内核

如何从另一个if条件中的一个if条件中获取变量的值?

shell if 语句