Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_weekendowa_20221008
Commits
a13e42f5
Commit
a13e42f5
authored
Nov 26, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adnotacje Bean Validation
parent
c2da37f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
1 deletions
+25
-1
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+1
-0
Customer.java
PC30-SklepSpring/src/main/java/sklep/model/Customer.java
+5
-0
OrderProduct.java
PC30-SklepSpring/src/main/java/sklep/model/OrderProduct.java
+10
-1
Product.java
PC30-SklepSpring/src/main/java/sklep/model/Product.java
+9
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
a13e42f5
...
...
@@ -92,6 +92,7 @@ public class ProductController {
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// i nie trzeba dodawać go w osobnym poleceniu.
try
{
// Gdy próbujemy wywołać save, a obiekt nie spełnia wymagań validation, to wtedy Hibernate zablokuje taki zapis (wyrzuci wyjątek).
productRepository
.
save
(
product
);
model
.
addAttribute
(
"saved"
,
true
);
}
catch
(
Exception
e
)
{
...
...
PC30-SklepSpring/src/main/java/sklep/model/Customer.java
View file @
a13e42f5
...
...
@@ -2,6 +2,9 @@ package sklep.model;
import
java.io.Serializable
;
import
javax.persistence.*
;
import
javax.validation.constraints.Email
;
import
javax.validation.constraints.Pattern
;
import
java.util.List
;
...
...
@@ -17,6 +20,7 @@ public class Customer implements Serializable {
@Id
@Column
(
name
=
"customer_email"
)
@Email
private
String
customerEmail
;
private
String
address
;
...
...
@@ -29,6 +33,7 @@ public class Customer implements Serializable {
private
String
phoneNumber
;
@Column
(
name
=
"postal_code"
)
@Pattern
(
regexp
=
"\\d{2}-\\d{3}"
)
private
String
postalCode
;
//bi-directional many-to-one association to Order
...
...
PC30-SklepSpring/src/main/java/sklep/model/OrderProduct.java
View file @
a13e42f5
package
sklep
.
model
;
import
java.io.Serializable
;
import
javax.persistence.*
;
import
java.math.BigDecimal
;
import
javax.persistence.Column
;
import
javax.persistence.EmbeddedId
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.NamedQuery
;
import
javax.persistence.Table
;
import
javax.validation.constraints.Min
;
/**
* The persistent class for the order_products database table.
...
...
@@ -24,6 +32,7 @@ public class OrderProduct implements Serializable {
@Column
(
name
=
"actual_vat"
)
private
BigDecimal
actualVat
;
@Min
(
1
)
private
Integer
quantity
;
//bi-directional many-to-one association to Order
...
...
PC30-SklepSpring/src/main/java/sklep/model/Product.java
View file @
a13e42f5
...
...
@@ -2,6 +2,11 @@ package sklep.model;
import
java.io.Serializable
;
import
javax.persistence.*
;
import
javax.validation.constraints.DecimalMin
;
import
javax.validation.constraints.Min
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.math.BigDecimal
;
/**
...
...
@@ -21,11 +26,15 @@ public class Product implements Serializable {
private
String
description
;
@DecimalMin
(
"0.01"
)
private
BigDecimal
price
;
@Column
(
name
=
"product_name"
)
@NotNull
@Size
(
min
=
3
,
max
=
10
)
private
String
productName
;
@Min
(
0
)
private
BigDecimal
vat
;
public
Product
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment