1、发现问题java
<select id="queryStudentByNum" resultType="student" parameterType="string"> 对象
select num,name,phone from student
<where>
<if test = " num!=null and num!='' ">
AND num = #{num}
</if>
</where>
</select>
Mybatis查询传入一个字符串传参数,报There is no getter for property named 'num' in 'class java.lang.String'。
字符串
2、解决问题get
<select id="queryStudentByNum" resultType="student" parameterType="string"> string
select num,name,phone from student
<where>
<if test = " _parameter!=null and_parameter!='' ">
AND num = #{_parameter}
</if>
</where>
</select>
不管参数名,都要改为"_parameter"。
class
3、缘由分析test
Mybatis默认采用ONGL解析参数,因此会自动采用对象树的形式取string.num值,引发报错。也能够public List methodName(@Param(value="num") String num)的方法说明参数值List