DTO 查询

我们可以将查询指定为 SQL,并自动将其映射到 DTO bean 中。

在典型的近期应用程序中,大约 10% 的查询是 DTO 查询。

public class CustomerDto {

  Integer id;
  String name;

  ... // getters & setters
}

List<CustomerDto> beans =
  DB.findDto(CustomerDto.class, "select id, name from customer where name = ?")
  .setParameter(1, "Rob")
  .findList();

  
class CustomerDto {

  var id: Int = 0
  var name: String? = null
}

val beans =
  DB.findDto(CustomerDto::class.java, "select id, name from customer where name = ?")
  .setParameter(1, "Rob")
  .findList()