用mybatis插入语句时报错:There is no getter for property named 'DictionaryType' in 'class com.bjpowernode.crm.domain.DictionaryType'
代码如下:
public int insertDictionaryType(DictionaryType dictionaryType) {
SqlSessionFactory sqlSessionFactory = null;
SqlSession sqlSession = null;
int num = 0;
try {
sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(Resources.getResourceAsStream("mybatis-config.xml"));
sqlSession = sqlSessionFactory.openSession();
dictionaryType.setCode(UUIDGenerator.generate());
num = sqlSession.insert("insertDictionaryType", dictionaryType);
sqlSession.commit();
} catch (IOException e) {
if (sqlSession != null) {
sqlSession.rollback();
}
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
return num;
}
mapper.xml配置如下:
<mapper namespace="com.bjpowernode.crm.domain">
<insert id="insertDictionaryType" parameterType="DictionaryType">
insert into
tbl_dic_type
values
(#{DictionaryType.code},#{DictionaryType.name},#{DictionaryType.description})
</insert>
</mapper>
DictionaryType类信息如下:
public class DictionaryType {
private String code;
private String name;
private String description;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
xml的insert语句去掉前面的DictionaryType即可