Commit 31b71fc5 by Patryk Czarnik

Dodanie adnotacji Jakarta Validation

parent 01d153dc
package sklep.model; package sklep.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
...@@ -10,6 +12,7 @@ import java.util.Set; ...@@ -10,6 +12,7 @@ import java.util.Set;
public class Customer { public class Customer {
@Id @Id
@Column(name = "customer_email", nullable = false, length = 100) @Column(name = "customer_email", nullable = false, length = 100)
@Email
private String customerEmail; private String customerEmail;
@Column(name = "customer_name", nullable = false, length = 100) @Column(name = "customer_name", nullable = false, length = 100)
...@@ -22,6 +25,7 @@ public class Customer { ...@@ -22,6 +25,7 @@ public class Customer {
private String address; private String address;
@Column(name = "postal_code", length = 10) @Column(name = "postal_code", length = 10)
@Pattern(regexp="[0-9]{2}-[0-9]{3}")
private String postalCode; private String postalCode;
@Column(name = "city", length = 100) @Column(name = "city", length = 100)
......
package sklep.model; package sklep.model;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -16,12 +17,17 @@ public class Product { ...@@ -16,12 +17,17 @@ public class Product {
private Integer id; private Integer id;
@Column(name = "product_name", nullable = false, length = 100) @Column(name = "product_name", nullable = false, length = 100)
@NotBlank
@Size(min=1, max=20)
private String productName; private String productName;
@Column(name = "price", nullable = false, precision = 10, scale = 2) @Column(name = "price", nullable = false, precision = 10, scale = 2)
@DecimalMin("0.01")
@DecimalMax("99999.99") // ceny od 100 tys nie będą akceptowane
private BigDecimal price; private BigDecimal price;
@Column(name = "vat", precision = 2, scale = 2) @Column(name = "vat", precision = 2, scale = 2)
@Min(0)
private BigDecimal vat; private BigDecimal vat;
@Column(name = "description", length = Integer.MAX_VALUE) @Column(name = "description", length = Integer.MAX_VALUE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment