apuntes:spring_web
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
apuntes:spring_web [2021/11/21 23:37] – [Plantillas. Thymeleaf] Santiago Faci | apuntes:spring_web [2021/11/21 23:43] (current) – [Relaciones entre clases] Santiago Faci | ||
---|---|---|---|
Line 258: | Line 258: | ||
===== Modelo de datos ===== | ===== Modelo de datos ===== | ||
+ | <code java> | ||
+ | @Data | ||
+ | @AllArgsConstructor | ||
+ | @NoArgsConstructor | ||
+ | @Entity(name = " | ||
+ | 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; | ||
+ | } | ||
+ | </ | ||
==== Relaciones entre clases ==== | ==== Relaciones entre clases ==== | ||
+ | <code java> | ||
+ | @Data | ||
+ | @AllArgsConstructor | ||
+ | @NoArgsConstructor | ||
+ | @Entity(name = " | ||
+ | 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 = " | ||
+ | private User user; | ||
+ | @ManyToOne | ||
+ | @JoinColumn(name = " | ||
+ | private Category category; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code java> | ||
+ | @Data | ||
+ | @AllArgsConstructor | ||
+ | @NoArgsConstructor | ||
+ | @Entity(name = " | ||
+ | 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 = " | ||
+ | private LocalDate birthDate; | ||
+ | |||
+ | @OneToMany(mappedBy = " | ||
+ | private List< | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code java> | ||
+ | @Data | ||
+ | @AllArgsConstructor | ||
+ | @NoArgsConstructor | ||
+ | @Entity(name = " | ||
+ | public class Category { | ||
+ | |||
+ | @Id | ||
+ | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
+ | private long id; | ||
+ | @Column | ||
+ | private String name; | ||
+ | @Column | ||
+ | private String description; | ||
+ | @Column | ||
+ | private float discount; | ||
+ | |||
+ | @OneToMany(mappedBy = " | ||
+ | private List< | ||
+ | } | ||
+ | </ | ||
===== Gestión de errores ===== | ===== Gestión de errores ===== | ||
Line 280: | Line 385: | ||
public ProductNotFoundException() { | public ProductNotFoundException() { | ||
super(); | super(); | ||
- | } | + | |
} | } | ||
</ | </ | ||
Line 290: | Line 395: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | <file html product_error.html> | ||
+ | < | ||
+ | <html lang=" | ||
+ | < | ||
+ | <meta charset=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | <p>El producto que intentas localizar no está disponible</ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
<code java> | <code java> | ||
Line 298: | Line 417: | ||
</ | </ | ||
+ | <file html error.html> | ||
+ | < | ||
+ | <html lang=" | ||
+ | < | ||
+ | <meta charset=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | <p>La página que has solicitado no está disponible</ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
===== Plantillas. Thymeleaf ===== | ===== Plantillas. Thymeleaf ===== | ||
apuntes/spring_web.1637537855.txt.gz · Last modified: 2021/11/21 23:37 by Santiago Faci