一. 背景

   由于架构支持了一对一,以及一对多的查询,对查询返回结果进行了处理。返回的结果都是dto,而不是数据库实体映射类vo。不过实体新增,修改,软删操作都是传vo。

二. 实例

  这里有t_test_a,t_test_b两张表,每张表都会有与数据库映射的实体类TestAVo和TestBVo,以及查询返回结果TestADto和TestBDto。

CREATE TABLE `t_test_a` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `c_id` bigint(20) DEFAULT NULL COMMENT 'c主键',
  `b_id` bigint(20) DEFAULT NULL COMMENT 'b主键',
  `a_id` bigint(20) DEFAULT NULL COMMENT 'a主键',
  `crt_tm` datetime DEFAULT NULL COMMENT '创建时间',
  `crt_by` varchar(32) DEFAULT NULL COMMENT '创建人',
  `upd_tm` datetime DEFAULT NULL COMMENT '修改时间',
  `upd_by` varchar(32) DEFAULT NULL COMMENT '修改人',
  `edit_flag` tinyint(4) DEFAULT '0' COMMENT '逻辑删除',
  `tnt_id` bigint(20) DEFAULT NULL COMMENT '租户主键',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试A';
CREATE TABLE `t_test_b` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `a_id` bigint(20) DEFAULT NULL COMMENT 'a主键',
  `c_id` bigint(20) DEFAULT NULL COMMENT 'c主键',
  `crt_tm` datetime DEFAULT NULL COMMENT '创建时间',
  `crt_by` varchar(32) DEFAULT NULL COMMENT '创建人',
  `upd_tm` datetime DEFAULT NULL COMMENT '修改时间',
  `upd_by` varchar(32) DEFAULT NULL COMMENT '修改人',
  `edit_flag` tinyint(4) DEFAULT '0' COMMENT '逻辑删除',
  `tnt_id` bigint(20) DEFAULT NULL COMMENT '租户主键',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试B';
/**
 * <p>
 * 测试A
 * </p>
 *
 * @author yuyi ([email protected])
 * @since 2019-03-20
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_test_a")
public class TestAVo extends BaseVo {
    private static final long serialVersionUID = 1L;

    @Note("主键")
    private Long id;

    @Note("c主键")
    private Long cId;

    @Note("b主键")
    private Long bId;

    @Note("a主键")
    private Long aId;

}
/**
 * <p>
 * 测试B
 * </p>
 *
 * @author yuyi ([email protected])
 * @since 2019-03-20
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_test_b")
public class TestBVo extends BaseVo {
    private static final long serialVersionUID = 1L;

    @Note("主键")
    private Long id;

    @Note("a主键")
    private Long aId;

    @Note("c主键")
    private Long cId;

}
/**
 * <p>
 * 测试A
 * </p>
 *
 * @author yuyi ([email protected])
 */
@Data
public class TestADto implements Serializable {
    private static final long serialVersionUID = 1L;

    protected TestAVo testAVo2;
    protected TestAVo testAVo;
    protected TestBVo testBVo;
    protected TestCVo testCVo;
    protected TestDVo testDVo;
    protected List<TestBDto> testBList;
    protected List<TestCDto> testCList;

}
/**
 * <p>
 * 测试B
 * </p>
 *
 * @author yuyi ([email protected])
 * @since 2019-03-20
 */
@Data
public class TestBDto implements Serializable {
    private static final long serialVersionUID = 1L;

    protected TestBVo testBVo;
    protected TestCVo testCVo;

}

这样便于连表查询返回对象

05-07 08:37