记录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} ")