首页 > 代码库 > There is no getter for property named xxx' in 'class java.lang.xxx'
There is no getter for property named xxx' in 'class java.lang.xxx'
在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="http://www.mamicode.com/tj") String tj);
There is no getter for property named xxx' in 'class java.lang.xxx'