Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
5b2a3121
Commit
5b2a3121
authored
Jul 29, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adnotacje Validation
parent
3308d7e0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
0 deletions
+23
-0
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+3
-0
Customer.java
PC27-SklepSpring/src/main/java/sklep/model/Customer.java
+5
-0
OrderProduct.java
PC27-SklepSpring/src/main/java/sklep/model/OrderProduct.java
+8
-0
Product.java
PC27-SklepSpring/src/main/java/sklep/model/Product.java
+7
-0
No files found.
PC27-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
5b2a3121
...
...
@@ -58,9 +58,12 @@ public class ProductController {
@PostMapping
({
"/{id}/edit"
,
"/new"
})
public
String
saveProduct
(
Product
product
)
{
// W tej wersji dane z wypełnionego formularza odbieramy w postaci jednego obiektu Product.
// Na taki obiekt mówi się czasami "form backing bean".
// Spring sam wpisze dane do pól o takich samych nazwach.
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// Gdyby obiekt nie spełniał warunków walidacji, to zostanie odrzucony przez metodę save. Będzie wyjątek.
System
.
out
.
println
(
"id przed zapisem: "
+
product
.
getProductId
());
productRepository
.
save
(
product
);
System
.
out
.
println
(
"id po zapisie: "
+
product
.
getProductId
());
...
...
PC27-SklepSpring/src/main/java/sklep/model/Customer.java
View file @
5b2a3121
...
...
@@ -2,6 +2,9 @@ package sklep.model;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.Email
;
import
jakarta.validation.constraints.Pattern
;
import
java.util.List
;
...
...
@@ -17,6 +20,7 @@ public class Customer implements Serializable {
@Id
@Column
(
name
=
"customer_email"
,
updatable
=
false
)
@Email
private
String
customerEmail
;
private
String
address
;
...
...
@@ -30,6 +34,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
...
...
PC27-SklepSpring/src/main/java/sklep/model/OrderProduct.java
View file @
5b2a3121
...
...
@@ -2,6 +2,10 @@ package sklep.model;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.DecimalMax
;
import
jakarta.validation.constraints.DecimalMin
;
import
jakarta.validation.constraints.Min
;
import
java.math.BigDecimal
;
...
...
@@ -19,11 +23,15 @@ public class OrderProduct implements Serializable {
private
OrderProductPK
id
;
@Column
(
name
=
"actual_price"
)
@DecimalMin
(
"0.01"
)
private
BigDecimal
actualPrice
;
@Column
(
name
=
"actual_vat"
)
@DecimalMin
(
"0.00"
)
@DecimalMax
(
"0.99"
)
private
BigDecimal
actualVat
;
@Min
(
1
)
private
Integer
quantity
;
//bi-directional many-to-one association to Order
...
...
PC27-SklepSpring/src/main/java/sklep/model/Product.java
View file @
5b2a3121
...
...
@@ -2,6 +2,8 @@ package sklep.model;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.*
;
import
java.math.BigDecimal
;
...
...
@@ -22,11 +24,16 @@ public class Product implements Serializable {
private
String
description
;
@NotNull
@DecimalMin
(
"0.01"
)
private
BigDecimal
price
;
@Column
(
name
=
"product_name"
)
@NotBlank
private
String
productName
;
@DecimalMin
(
"0.00"
)
@DecimalMax
(
"0.99"
)
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