【问题标题】:Mybatis @Insert Error: nested exception is org.apache.ibatis.reflection.ReflectionExceptionMybatis @Insert 错误:嵌套异常是 org.apache.ibatis.reflection.ReflectionException
【发布时间】:2018-11-19 11:44:25
【问题描述】:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'testStr' in 'class Test.TestModel'.

错误出现在以下方法中:

public interface TestMapper {
    @Insert({"INSERT INTO PLUProps.Test VALUES(#{id}, #{testStr})"})
    int insertData(TestModel testModel);
}

//Test
private int insertData(){
    TestModel testModel = new TestModel();
    testModel.setId(1);
    testModel.setTestSTr("123123");
    return testMapper.insertData(testModel);
}

在TestModel的实体类中,我使用lombok的@Data注解自动生成setter和getter方法。

@Data
public class TestModel implements Serializable {
    private static final long serialVersionUID = -1180681799256416275L;
    private int id;
    private String testSTr;
}

这个错误是我写错了@Insert语句引起的吗?谢谢。

【问题讨论】:

    标签: spring-boot mybatis


    【解决方案1】:

    此处输入错误。

    错误抱怨 getter 和 setter 所以

    private String testSTr; 更改为private String testStr; 并相应地创建getter 和setter。

    #{testStr}) 更改为#{testSTr})

    【讨论】:

    • 哦...我的错误...谢谢。
    • 快乐编码...:)
    【解决方案2】:

    您的查询或字段中有错字。

    该字段被命名为testSTr(注意大写的T)所以声明应该是

    INSERT INTO PLUProps.Test VALUES(#{id}, #{testSTr})
    

    或者将字段名称更改为testStr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 2011-12-11
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多