关于myBatis:org.apache.ibatis.reflection.ReflectionException: There is no getter for property in实例类'

1 篇文章 0 订阅
1 篇文章 0 订阅

报错:Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'user_name' in 'class com.kushun.pojo.User'

注意:user_name 是个表字段,后面应该对应是属性值userName

属性值看实体类User里定义的字段

// 用户名

private String userName;

 

实体类User

package com.kushun.pojo;

import java.util.Date;

public class User {

    private Long id;

    // 用户名
    private String userName;

    // 密码
    private String password;

    // 姓名
    private String name;

    // 年龄
    private Integer age;

    // 性别,1男性,2女性
    private Integer sex;

    // 出生日期
    private Date birthday;

    // 创建时间
    private Date created;

    // 更新时间
    private Date updated;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getuserName() {
        return userName;
    }

    public void setuserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    @Override
    public String toString() {
        return "User [id=" + id + ", userName=" + userName + ", password=" + password + ", name=" + name
                + ", age=" + age + ", sex=" + sex + ", birthday=" + birthday + ", created=" + created
                + ", updated=" + updated + "]";
    }

}

Mybatis里:UserMapper.XML,错误的写法如下:

<!--添加用户-->
    <insert id="insertUser" parameterType="User">
        insert into tb_user (id,user_name,password,name,age,sex,birthday,created,updated)
        values(null,#{user_name},#{password},#{name},#{age},#{sex},#{birthday},now(),now());
    </insert>
    <!--修改用户-->
    <update id="updateUser" parameterType="User">
        update tb_user
        set user_name=#{user_name},
        password=#{password},
        name=#{name},
        age=#{age},
        sex=#{sex},
        birthday=#{birthday},
        updated=#{updated}
        where id=#{id};
    </update>

 

正确的写法:

这里user_name 是个表字段和

后面的#{user_name} 这里错了,应该

写成#{userName},应该是属性值 

虽然是小问题,但是不好查

一开始百度了很多 有的人是属性名写错了,有的是没有set/get  

总结到此分享一下 有此情况错误的 一般就这几种了希望可以帮助到大家。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值