There is no getter for property named xxx' in 'class java.lang.xxx'
阿新 • • 發佈:2017-08-12
public med 入參 ren 說明 _id lang list val
<if test="_parameter">
and AREA_ID=#{_parameter}
</if>
</sql>
<sql id="Base_Column_List">
ID,DEPT_NAME,USER_NAME,JOB_NAME,DAYS,ENTRY_CORE,AREA_ID,AREA_NAME
</sql>
<select id="findAllCarEntry" parameterType="int" resultMap="resultMap">
select <include refid="Base_Column_List"/> from vie_car_entry_top
<where>
<include refid="whereCadtion"/>
</where>
</select>
在xxxMapper.xml我們使用sql片段來提高sql代碼的復用性,當時新手傳入參數時常常出現這樣的錯誤:
There is no getter for property named xxx‘ in ‘class java.lang.xxx‘
①出現的原因:我們實體類中有getter方法,為啥mybatis無法識別呢,原來Mybatis默認采用ONGL解析參數,所以會自動采用對象樹形式來取java.lang.xxx.xxx值,所以引起報錯。
②解決方法: 1)將傳入參數改為_parameter這樣就可以了,例如:
<sql id="whereCadtion">
<if test="_parameter">
and AREA_ID=#{_parameter}
</if>
</sql>
<sql id="Base_Column_List">
ID,DEPT_NAME,USER_NAME,JOB_NAME,DAYS,ENTRY_CORE,AREA_ID,AREA_NAME
</sql>
<select id="findAllCarEntry" parameterType="int" resultMap="resultMap">
select <include refid="Base_Column_List"/> from vie_car_entry_top
<where>
<include refid="whereCadtion"/>
</where>
</select>
2)將接口參數名說明參數值。例如:
public List methodName(@Param(value="tj") String tj);
There is no getter for property named xxx' in 'class java.lang.xxx'