User Tools

Site Tools


apuntes:spring_web

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
apuntes:spring_web [2021/11/21 23:39] – [Modelo de datos] Santiago Faciapuntes:spring_web [2021/11/21 23:41] – [Relaciones entre clases] Santiago Faci
Line 286: Line 286:
 ==== Relaciones entre clases ==== ==== Relaciones entre clases ====
  
 +<code java>
 +@Data
 +@AllArgsConstructor
 +@NoArgsConstructor
 +@Entity(name = "products")
 +public class Product {
 +
 +    @Id
 +    @GeneratedValue(strategy = GenerationType.IDENTITY)
 +    private long id;
 +    @Column
 +    private String name;
 +    @Column
 +    private String description;
 +    @Column
 +    private String category;
 +    @Column
 +    private float price;
 +    @Column
 +    private LocalDateTime creationDate;
 +    @Column
 +    private String observations;
 +    @Column
 +    private int quantity;
 +    
 +    @ManyToOne
 +    @JoinColumn(name = "user_id")
 +    private User user;
 +}
 +</code>
 +
 +<code java>
 +@Data
 +@AllArgsConstructor
 +@NoArgsConstructor
 +@Entity(name = "users")
 +public class User {
 +
 +    @Id
 +    @GeneratedValue(strategy = GenerationType.IDENTITY)
 +    private long id;
 +    @Column
 +    private String dni;
 +    @Column
 +    private String name;
 +    @Column
 +    private String surname;
 +    @Column(name = "birth_date")
 +    private LocalDate birthDate;
 +
 +    @OneToMany(mappedBy = "user")
 +    private List<Product> products;
 +}
 +</code>
 ===== Gestión de errores ===== ===== Gestión de errores =====
  
apuntes/spring_web.txt · Last modified: 2021/11/21 23:43 by Santiago Faci