The if tag in mybatis xml judges that the parameter is the value of int

The code with the problem:
the following is the xml statement of mybatis


<select id="userList" resultType="com.sxkj.example.user" parameterType="com.sxkj.example.user">
      select * from good
        <where>
            <if test="userid!=null and userid!=''">
                userid=#{userid}
            </if>
            <if test="state!=null and state='' ">
                and state=#{state}
            </if>       
        </where>
        order by id desc
    </select>

The state field is of type int. If the parameter state is 0, the condition of not being able to enter the state will result in no data being selected by swiping.
Because when the value of state is 0, its data type is Integer, so this judgment is false, and Mybatis thinks 0 is ' '

Solution;


<if test="state!=null ">
     and state=#{state}
</if> 

Guess you like

Origin blog.csdn.net/qq_39236283/article/details/126320400