我有以下域对象并定义了DTO。
Country.java
@Data
@Entity
public class Country extends ResourceSupport {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long countryID;
@NotBlank(message = "Country name is a required field")
private String countryName;
private Str
我有一堂课:
public class Participant
{
[Key]
public int ParticipantId { get; set; }
[Column(TypeName ="nvarchar(50)")]
public string Email { get; set; }
[Column(TypeName = "nvarchar(50)")]
public string Name { get; set; }
public int Score { get; set; }
我正在构建一个API,其中包括需要处理用户的API。我正在用C# 10和.NET 6构建它。为了在API端点中接收/返回数据,我使用记录。因此,例如,这可能是返回所有用户的终结点:
[HttpGet]
public IActionsResult ListUsers()
{
// The '.AsDto' method extracts the relevant information
// from the domain model 'User' in the form of a record (dto).
List<UserDto
我们有一个ASP.NET Web,它为我们的单个页面应用程序提供了REST。我们使用DTO/POCOs通过这个API传递数据。
现在的问题是,随着时间的推移,这些DTO变得越来越大,所以现在我们要重构DTO。
我正在寻找如何设计DTO的“最佳实践”:目前我们有一些只包含值类型字段的小型DTO,例如:
public class UserDto
{
public int Id { get; set; }
public string Name { get; set; }
}
其他DTO按组合使用此UserDto,例如:
public class TaskDto
{
publ
在不同的API端点中对同一个实体使用多个DTO是一个很好的实践。例如:我有一个api端点,它指控以下Dto:
public class AddressDto
{
public string City { get; set; }
public string Country { get; set; }
public string Contact { get; set; }
public string Street1 { get; set; }
public string Street2 { get; set; }
public string Stat
我有一个域对象图,我需要构建一个DTO来将其发送到视图。如何正确地设计它?我看到了两个选项,我可以将DTO构建代码放在哪里:
1)到DTO构造函数中。但是,域对象必须通过getter将所有字段呈现给DTO,所以它不是DDD。
public DTO(DomainObject domain) {
/// access internal fields of different domain object.
}
2)进入域对象。访问字段不会有任何问题,但是当添加新视图时,域对象会增长得非常快。
public DTO1 createDTO1() {
...
}
public DTO2 c
当使用Spring控制器中的PUT请求方法部分更新实体时,我试图区分空值和未提供值。
以下列实体为例:
@Entity
private class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/* let's assume the following attributes may be null */
private String firstName;
private String lastName;
/*
我在一个应用程序中有一个端点,我想在另一个应用程序中创建端点,该应用程序将调用第一个端点。 第一个是 @AllArgsConstructor
@RestController
@RequestMapping(PASSWORD_RESET)
public class ResetPasswordController {
private final ResetPasswordService passwordService;
private final AgentUtils agentUtils;
private final ObjectMapper objectMapper;
我正在尝试将映射应用于导航属性,但我得到一个错误。我有两个包含一对多导航属性的类。 public class Contractor : Entity<string>
{
public virtual Collection<DocsVat> DocsVats { get; set; }
}
public class DocsVat : Entity<Guid>
{
public Contractor Contractor { get; set; }
} 配置为: public class DocsVatEntityConfigurat