Mybatis @Insert Error: nested exception is org.apache.ibatis.reflection.ReflectionException
Mybatis @Insert Error: nested exception is org.apache.ibatis.reflection.ReflectionException
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的实体class中,我使用lombok的@Data注解自动生成setter和getter方法
@Data
public class TestModel implements Serializable {
private static final long serialVersionUID = -1180681799256416275L;
private int id;
private String testSTr;
}
是不是我@Insert语句写错导致的?谢谢
此处打字错误。
错误抱怨 getters 和 setters 所以
将 private String testSTr;
更改为 private String testStr;
并相应地创建 getter 和 setter。
或
将#{testStr})
更改为#{testSTr})
您在查询或字段中有错字。
字段名为 testSTr
(注意大写字母 T
),因此语句应为
INSERT INTO PLUProps.Test VALUES(#{id}, #{testSTr})
或者将字段名称更改为 testStr
。
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的实体class中,我使用lombok的@Data注解自动生成setter和getter方法
@Data
public class TestModel implements Serializable {
private static final long serialVersionUID = -1180681799256416275L;
private int id;
private String testSTr;
}
是不是我@Insert语句写错导致的?谢谢
此处打字错误。
错误抱怨 getters 和 setters 所以
将 private String testSTr;
更改为 private String testStr;
并相应地创建 getter 和 setter。
或
将#{testStr})
更改为#{testSTr})
您在查询或字段中有错字。
字段名为 testSTr
(注意大写字母 T
),因此语句应为
INSERT INTO PLUProps.Test VALUES(#{id}, #{testSTr})
或者将字段名称更改为 testStr
。