Skip to content

BEP 55:实体类 内嵌对象 与 列表 #55

@troyzhxu

Description

@troyzhxu

实体类内 支持嵌套 对象

用法1:内嵌对象

@SearchBean(tables="user u, profile p", joinCond="u.id = p.user_id")
public class User {

    // 和主表数据在同一个 SQL 查出来,参数 value=p 指定该对象的数据来自 profile 表
    @DbFiled(type=DbType.INLINE, value="p")
    private Profile profile;        

    // 省略其它...
}

public class Profile {

    private String address;

    // 省略其它...
}

用法2:内嵌列表

@SearchBean(tables="user u, user_role ur, role r", joinCond="u.id = ur.user_id and ur.role_id = r.id")
public class User {

    private Long id;

    // 类似 mybatis 的 <collection> 标签
    // 和主表数据在同一个 SQL 查出来,value=r 指定该集合的数据来自 role 表
    @DbFiled(type=DbType.COLLECTION, value="r")
    private List<Role> roles;

    // 省略其它...
}

public class Role {

    private Long id;

    // 省略其它...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions