Alan_Xiang 2017-01-04 12:23 采纳率: 0%
浏览 2154
已结题

mybatis generator能否通过生成成员类的方式实现关联关系

例如现在有Department和Employee的一对多关联关系,通过hibernate逆向生成实体类时,在Employee类中是这样的反映关联关系的:

 private Department department;

感觉这样在查询employee和department关系时比较方便,但是通过mybatis generator逆向生成时,在Employee中是这样反映的:

 private Integer departmentId;

即hibernate中是通过成员类,而mybatis中是通过外键字段,我知道这样也可以实现,但是觉得不如上面的方法方便,请问是否可以通过某种配置更改?

  • 写回答

3条回答 默认 最新

  • JE_GE 2017-01-04 12:57
    关注
     <select id="findAll" resultMap="resultMapUser">
            select u.id,u.name,u.age,d.id did,d.name dname
            from t_user u join t_dept d
            on
            u.dept_id=d.id
        </select>
    
        <resultMap type="User" id="resultMapUser">
            <id column="id" property="id" />
            <result column="name" property="name" />
            <result column="age" property="age" />
            <association property="dept" javaType="Dept">
                <id column="did" property="id" />
                <result column="dname" property="name" />
            </association>
        </resultMap>
    
    评论

报告相同问题?