異常: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