例如现在有Department和Employee的一对多关联关系,通过hibernate逆向生成实体类时,在Employee类中是这样的反映关联关系的:
private Department department;
感觉这样在查询employee和department关系时比较方便,但是通过mybatis generator逆向生成时,在Employee中是这样反映的:
private Integer departmentId;
即hibernate中是通过成员类,而mybatis中是通过外键字段,我知道这样也可以实现,但是觉得不如上面的方法方便,请问是否可以通过某种配置更改?
<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>
public class User {
private Long id;
private String name;
private Integer age;
private Dept dept;
public class Dept {
private Long id;
private String name;
楼主,你现在解决了这个问题了吗?我也想让它自动生成一个类中含有其他类型引用的变量,而不是单纯的基本类型变量