cocobear9  
一枚普通的zisuer(lll¬ω¬),努力每天多学一点点

UserMapper接口中的方法

//条件查询
    public abstract List<User> selectByCondition(User user,int start,int limit);

传入了3个参数

在UserMapper.xml中

<select id="selectByCondition" resultType="user" parameterType="user" >
        select * from user
        <where>
            <if test="username != null ">
                and username like concat('%',#{username},'%')
            </if>
            <if test="phone != null ">
                and phone = #{phone}
            </if>

        </where>
        limit #{param2},#{param3}
    </select>

 

 

 

 解决:因为传入了3个参数,那我limit 地方用了 #{param2},#{param3},那么上面parameterType就可以不用写了,因为用下表来代表传入的参数
所以把mapper.xml中sql语句改成

 <select id="selectByCondition" resultType="user" >
        select * from user
        <where>
            <if test="param1.username != null and param1.username != ''">
                and username like concat('%',#{param1.username},'%')
            </if>
            <if test="param1.age != null and param1.age != ''">
                and age like concat('%',#{param1.age},'%')
            </if>
            <if test="param1.phone != null and param1.phone != ''">
                and phone like concat('%',#{param1.phone},'%')
            </if>
        </where>
        limit #{param2},#{param3}
    </select>

 

 

 

posted on 2020-10-24 14:26  cocobear9  阅读(3178)  评论(0)    收藏  举报