There is no getter for property named 'xxx' in 'class.....'

本文介绍了解决MyBatis中因字段映射不一致导致的错误方法。通过对比XML配置文件中的字段名与实体类中的属性名,确保二者一致以避免运行时错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mybatis  There is no getter for property named 'xxx' in 'class.....'

在确定该字段在entity中添加了get set方法之后,通常情况报这个错是因为mapper.xml中名称没有保持一致导致的。


<!-- 结果Map -->
	<resultMap id="BaseResultMap" type="com.business.monitor.BaseEquipmentEntity">
		<result property="relationId" jdbcType="INTEGER" column="f_relation_id"/>
		<result property="equipmentId" jdbcType="VARCHAR" column="f_equipment_id"/>
		<result property="baseId" jdbcType="VARCHAR" column="f_base_id"/>
		<result property="host" jdbcType="VARCHAR" column="f_host"/>
		<result property="port" jdbcType="INTEGER" column="f_port"/>
		<result property="username" jdbcType="VARCHAR" column="f_username"/>
		<result property="password" jdbcType="VARCHAR" column="f_password"/>
		<result property="name" jdbcType="VARCHAR" column="f_name"/>
		<result property="remark" jdbcType="VARCHAR" column="f_remark"/>
		<result property="enterpriseId" jdbcType="VARCHAR" column="f_enterprise_id"/>
	</resultMap>

<!-- 分页查询 -->
<select id="queryByPage" parameterType="com.common.vo.ListVo.ListReqVO"
		resultMap="BaseResultMap">
		SELECT
                c.f_enterprise_id,
               c.f_relation_id,
		c.f_base_id,
		c.f_host,
		c.f_equipment_id,
		d.f_name,
		d.f_remark,
		FROM t_base_equipment AS c INNER JOIN t_internet_things_equipment AS d
		ON c.f_equipment_id = d.f_equipment_id
	<where>
	1=1
	<if test="whereCondition!=null">
	<if test="whereCondition.enterpriseId!=null">AND c.f_enterprise_id = #{whereCondition.enterpriseId,jdbcType=VARCHAR}</if>
	<if test="whereCondition.relationId!=null">AND f_relation_id = #{whereCondition.relationId,jdbcType=INTEGER}</if>
	<if test="whereCondition.host!=null and whereCondition.host!=''">AND f_host like CONCAT('%',#{whereCondition.host,jdbcType=VARCHAR},'%')</if>
	<if test="whereCondition.name!=null and whereCondition.name!=''">AND d.f_name like CONCAT('%',#{whereCondition.name,jdbcType=VARCHAR},'%')</if>
	</if>
	</where>
</select>

其中

<result property="enterpriseId" jdbcType="VARCHAR" column="f_enterprise_id"/>

 <if test="whereCondition.enterpriseId!=null">AND c.f_enterprise_id = #{whereCondition.enterpriseId,jdbcType=VARCHAR}</if>


//property的字段名称一致,column为数据库中字段名要一致,即例子中红色位置与红色一致,蓝色位置与蓝色一致。

//这是我在使用中遇到的问题及解决,当时名称未保持一致,出现如题的报错情况,将名称更正一致后,问题解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值