mybatis 参数传递

用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;
    }
}

阅读 1.8k
1 个回答

xml的insert语句去掉前面的DictionaryType即可

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题