动态SQL下模糊查询

DAO层接口
传入一个user对象

List<User> queryAllUser(User user);

mapper中用concat连接’%'与参数

    <select id="queryAllUser" resultType="com.qf.entity.User">
        select ID,PASSWORD,EMAIL,REAL_NAME,STATUS
        from admin_user
        <where>
            <if test="email!=null">
                email like concat('%',concat(#{email},'%'))
            </if>
            <if test="realName!=null">
                and real_name like concat('%',concat(#{realName},'%'))
            </if>
            <if test="status!=null">
                and status = #{status}
            </if>
        </where>
        order by  STATUS desc,id asc
    </select>

猜你喜欢

转载自blog.csdn.net/qq_41841482/article/details/108267761