Mybatis中傳參包There is no getter for property named 'XXX' in 'class java.lang.String'

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

相關文章
相關標籤/搜索