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>