1) is it better for repository to return entity or dto?
2) is the design in entity as good as the table structure in the database? Is it better to use associated objects?
example: define Entity entities
method 1:
@Entity
class Duty {
private Long creator; // ID
private Integer state; // ID
...
}
method 2:
@Entity
class Duty {
private Staff creator; //
private State state; //
}
do you think way 1 or way 2?
personally think:
- Mode 1 is more convenient when saving, while Mode 2 needs to create a corresponding Staff
, State object
- mode 2 can be returned directly to the front end when returning, while mode 1 still needs data processing when returning. After all, only ID value is taken out, and text value is also needed (how to deal with this? each record gets the text value from the database according to ID? )
what do you do when designing objects that store id and text separately? Are there any good design codes?