学无先后,达者为师

网站首页 编程语言 正文

MyBatis There is no getter for property named ‘xxx‘ in ‘class xxx‘问题解决

作者:embelfe_segge 更新时间: 2022-02-21 编程语言

问题描述:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘dataTime’ in ‘class com.dto.UserDto’

问题分析:

1、Mapper文件中参数出现了dataTime,但是实体类UserDto中却没有dataTime,两边无法映射导致报错。

    <insert id="create">
        INSERT INTO t_user(user_id,user_name,data_time)
        VALUES (#{item.userId,item.userName,item.dataTime})
    </insert>

public class UserDto {
    private Long userId;
    private String userName;
}

解决办法:

(1)Mapper文件去掉dataTime,实体类保持不变。

    <insert id="create">
        INSERT INTO t_user(user_id,user_name)
        VALUES (#{item.userId,item.userName})
    </insert>

(2)实体中添加dataTime,Mapper文件保持不变。

public class UserDto {
    private Long userId;
    private String userName;
    private Date dataTime;
}

原文链接:https://blog.csdn.net/embelfe_segge/article/details/123191204

栏目分类
最近更新