异常:Parameter 'username' not found. Available parameters are [arg1, arg0, param1, param2]


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>

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM