mybatis异常之There is no getter for property named 'xxx' in 'class xxx'

异常

org.apache.ibatis.reflection.ReflectionException:There is no getter for property named ‘xxx’ in ‘class xxx’
原因: 一般是 动态sql中 if test= " " 中出现参数不对应得情况

  1. mapper文件中入参参数与bean(model)中属性不对应
  2. 如果不是1中得原因,那就是mybatis部分版本出现得问题,需要将入参改为mybatis内置参数 _parameter即可

错误还原:

/**
 * 员工实体
 * @author Jerry
 * @create 2019-08-25 16:30
 */
public class Employee {
    private Integer empId;
    private String empName;
    private String email;
    private String gender;
    private String dId;
    ...get 省略
    ...set 省略
    }
    
数据库字段:
emp_id	emp_name	gender	email	d_id

/**
 * mapper接口
 * @author Jerry
 * @create 2019-08-25 16:30
 */
public interface EmployeeDynamicSqlMapper {
    /**
     * 根据条件查询员工信息if
     * @param employee
     * @return
     */
    List<Employee> getEmpsByConditionIf(Employee employee);
}
mapper.xml文件中得方法
<select id="getEmpsByConditionIf" resultType="Employee" parameterType="Employee">
        select emp_id empId,emp_name empName,gender,email,d_id dId from tbl_emp
        <where>
             <!--这里test中 如果empId写错,就会报上述异常-->
            <if test="empId!=null">
                emp_id=#{empId}
            </if>
            <if test="empName!=null and empName!=''">
                and emp_name like #{empName}
            </if>
            <if test="email!=null and email.trim()!=''">
                and email=#{email}
            </if>
            <if test="gender == 'M' and gender == 'WM' ">
                and gender=#{gender}
            </if>
            <if test="dId != null">
                and d_id=#{dId}
            </if>
        </where>
    </select>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值