spring-boot - 使用与 Spring Boot 存储库相同的存储库方法返回不同的 Dto
问题描述
我有两个 DTO 一个用于获取方法,例如“/pessoas/{id}”,另一个用于“/pessoas/{id}/detalhes”,我将在其中看到 Pessoa 的更多属性。
我的代码在 Kotlin 中。
我的简单 DTO:
interface PessoaDTO {
val idInstitucional: UUID?
val nome: String?
}
data class PessoaDTOImpl(override val idInstitucional: UUID?, override val nome: String?): PessoaDTO
我的 DTO 详细信息:
interface PessoaDetalhesDTO {
val idInstitucional: UUID?
val nome: String?
val email: String?
val telefone: String?
val cpf: Long?
}
data class PessoaDetalhesDTOImpl(override val idInstitucional: UUID?, override val nome: String?, override val email: String?, override val telefone: String?, override val cpf: Long?): PessoaDetalhesDTO
我有一个将由我的 PessoaController 访问的存储库。我正在考虑在我的存储库中使用两种方法,每种方法用于不同的 DTO。
那是我的存储库:
internal interface PessoaRepository : CrudRepository<Pessoa, Long>, JpaSpecificationExecutorWithProjection<Pessoa> {
fun findByIdInstitucional(idInstitucional: UUID): PessoaDTO?
fun findByIdInstitucional(idInstitucional: UUID): PessoaDetalhesDTO?
}
但是,对于不同的返回数据类型,我不能在存储库中有两个同名的函数。我该如何处理,而不必为 Pessoa 的详细信息创建另一个存储库?
解决方案
推荐阅读
- kubernetes - Windows 和 linux Kubernetes 集群上的 Windows 容器
- tensorflow - 使用 feature_column_lib.input_layer 进行张量流训练
- python - 如何使用代码中的系统调用对 git 中的根提交执行 git 命令?
- string - 使用 Python 2.7 根据字符串中的字母返回值
- javascript - 基于根键值的Joi数组对象验证
- javascript - firebase实时数据库获取匹配对象的键
- javascript - 从 angularfire 数据库列表订阅返回值
- python - 如何使用循环在 Python 中保存嵌套列表的元素并删除列表
- python - NotADirectoryError: [WinError 267] 目录名无效:'C:\\Users\\username\\MYD06_L2.A2008001.0000.006.2013341193524.hdf'
- bash - 从 Bash 变量中剥离字符 (2)