ReflectionException: There is no getter for property named ‘data’ in ‘class com.example.springboot.e

记录BUG

前后端分离项目

前端向后端更新一条数据(记住这个前提),前端控制台报错如下

PUT http://localhost:9090/user/update 500
response error: AxiosError: Request failed with status code 500

然后发现,后端也报错,后端报错信息更详细,所以从后端下手

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘data’ in ‘class com.example.springboot.entity.User’] with root cause

提取关键信息

There is no getter for property named ‘data’ in’class com.example.springboot.entity.User’

于是检查实体类User,发现getter是有的,但,写的是date

    private String date;
    public String getDate() {
        return date;
    }

并且数据库列名也是date
在这里插入图片描述

所以肯定是在某个代码写 “date”的时候,写成“data”。

刚开始说了,前端页面是向后端写入一条更新数据(前提的伏笔在这里),所以在后端项目,找有关update的语句,果不其然,错因在date = #{data},把data ,改成date,再重新运行后端项目后就没有这个bug了。

//错误的
@Update("update user set name = #{name}, date = #{data}, address = #{address} ,user_no = #{userNo} where id = #{id} ")


//修正的
@Update("update user set name = #{name}, date = #{date}, address = #{address} ,user_no = #{userNo} where id = #{id} ")
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值