问题描述:Parameter 'XX' not found. Available parameters are [1, 0, param1, param2......],传入的参数是一个对象。
粗心问题...0.0...
翻译过来就是找不到参数,可能是xml里的参数和mapper里的参数没正确关联起来导致报错
1.在需要传入多个参数时建议使用@Param(“xxx”)注解来标明参数
例:mapper.xml:
<select id="query" resultType="********.mapper.Student" >
select * from t_student
<where>
<if test="student.name != null and student.name != ''">
and name = #{student.name}
</if>
<if test="student.age != null">
and age = #{student.age}
</if>
</where>
</select>
其中圈出的部分原来由于粗心写成name,就会报错Parameter 's' not found.....
mapper:
有多个参数时建议用@param来标明,采用#{arg0}#{arg1},#{param1}#{param2}等方式要注意参数顺序。(当然还有其他绑定参数方法,这里不详细描述了)
List<Student> query(@Param("page")IPage<Student> page,
@Param("student")Student student);
2.注意导包时@param用的是apache,引用错了也会报错
import org.apache.ibatis.annotations.Param;
本次使用了@param注解,导包也没有出错,仍然报错,于是静下心来从头捋了一遍代码,发现是动态sql中<if text="这部分出错,由于参数是对象,所以要取对象中的属性"></if>