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
Next revision
Previous revision
apuntes:spring_web [2021/11/21 23:38] – [Gestión de errores] Santiago Faciapuntes: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 = "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;
 +}
 +</code>
 ==== 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;
 +    @ManyToOne
 +    @JoinColumn(name = "category_id")
 +    private Category category;
 +}
 +</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>
 +
 +<code java>
 +@Data
 +@AllArgsConstructor
 +@NoArgsConstructor
 +@Entity(name = "categories")
 +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 = "category")
 +    private List<Product> products;
 +}
 +</code>
 ===== Gestión de errores ===== ===== Gestión de errores =====
  
Line 312: Line 417:
 </code> </code>
  
 +<file html error.html>
 +<!DOCTYPE html>
 +<html lang="en">
 +<head>
 +    <meta charset="UTF-8">
 +    <title>Amazon</title>
 +</head>
 +<body>
 +<p>La página que has solicitado no está disponible</p>
 +<p>Vuelva a intentarlo más tarde</p>
 +</body>
 +</html>
 +</file>
 ===== Plantillas. Thymeleaf ===== ===== Plantillas. Thymeleaf =====
  
apuntes/spring_web.1637537919.txt.gz · Last modified: 2021/11/21 23:38 by Santiago Faci