Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
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
20230403
Commits
081e6cec
Commit
081e6cec
authored
Apr 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adnotacje Bean Validation
parent
4cc275e3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
1 deletions
+23
-1
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+1
-1
Customer.java
PC30-SklepSpring/src/main/java/sklep/model/Customer.java
+5
-0
OrderProduct.java
PC30-SklepSpring/src/main/java/sklep/model/OrderProduct.java
+5
-0
Product.java
PC30-SklepSpring/src/main/java/sklep/model/Product.java
+12
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
081e6cec
...
@@ -73,8 +73,8 @@ public class ProductController {
...
@@ -73,8 +73,8 @@ public class ProductController {
// W tej wersji dane z wypełnionego formularza odbieramy w postaci jednego obiektu Product.
// W tej wersji dane z wypełnionego formularza odbieramy w postaci jednego obiektu Product.
// Spring sam wpisze dane do pól o takich samych nazwach.
// Spring sam wpisze dane do pól o takich samych nazwach.
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// System.out.println("Obiekt przed zapisem: " + product.getProductId() + " " + product.getProductName());
System
.
out
.
println
(
"Obiekt przed zapisem: "
+
product
.
getProductId
()
+
" "
+
product
.
getProductName
());
productRepository
.
save
(
product
);
productRepository
.
save
(
product
);
System
.
out
.
println
(
"Obiekt po zapisie: "
+
product
.
getProductId
()
+
" "
+
product
.
getProductName
());
System
.
out
.
println
(
"Obiekt po zapisie: "
+
product
.
getProductId
()
+
" "
+
product
.
getProductName
());
return
"product_form"
;
return
"product_form"
;
...
...
PC30-SklepSpring/src/main/java/sklep/model/Customer.java
View file @
081e6cec
...
@@ -2,6 +2,9 @@ package sklep.model;
...
@@ -2,6 +2,9 @@ package sklep.model;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.Email
;
import
jakarta.validation.constraints.Pattern
;
import
java.util.List
;
import
java.util.List
;
...
@@ -17,6 +20,7 @@ public class Customer extends WspolnaNadklasa implements Serializable {
...
@@ -17,6 +20,7 @@ public class Customer extends WspolnaNadklasa implements Serializable {
@Id
@Id
@Column
(
name
=
"customer_email"
)
@Column
(
name
=
"customer_email"
)
@Email
private
String
customerEmail
;
private
String
customerEmail
;
private
String
address
;
private
String
address
;
...
@@ -30,6 +34,7 @@ public class Customer extends WspolnaNadklasa implements Serializable {
...
@@ -30,6 +34,7 @@ public class Customer extends WspolnaNadklasa implements Serializable {
private
String
phoneNumber
;
private
String
phoneNumber
;
@Column
(
name
=
"postal_code"
)
@Column
(
name
=
"postal_code"
)
@Pattern
(
regexp
=
"\\d{2}-\\d{3}"
)
private
String
postalCode
;
private
String
postalCode
;
//bi-directional many-to-one association to Order
//bi-directional many-to-one association to Order
...
...
PC30-SklepSpring/src/main/java/sklep/model/OrderProduct.java
View file @
081e6cec
...
@@ -2,6 +2,9 @@ package sklep.model;
...
@@ -2,6 +2,9 @@ package sklep.model;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.DecimalMin
;
import
jakarta.validation.constraints.Min
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
...
@@ -19,11 +22,13 @@ public class OrderProduct extends WspolnaNadklasa implements Serializable {
...
@@ -19,11 +22,13 @@ public class OrderProduct extends WspolnaNadklasa implements Serializable {
private
OrderProductPK
id
;
private
OrderProductPK
id
;
@Column
(
name
=
"actual_price"
)
@Column
(
name
=
"actual_price"
)
@DecimalMin
(
"0.01"
)
private
BigDecimal
actualPrice
;
private
BigDecimal
actualPrice
;
@Column
(
name
=
"actual_vat"
)
@Column
(
name
=
"actual_vat"
)
private
BigDecimal
actualVat
;
private
BigDecimal
actualVat
;
@Min
(
1
)
private
Integer
quantity
;
private
Integer
quantity
;
//bi-directional many-to-one association to Order
//bi-directional many-to-one association to Order
...
...
PC30-SklepSpring/src/main/java/sklep/model/Product.java
View file @
081e6cec
...
@@ -2,6 +2,12 @@ package sklep.model;
...
@@ -2,6 +2,12 @@ package sklep.model;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
jakarta.persistence.*
;
import
jakarta.persistence.*
;
import
jakarta.validation.constraints.DecimalMax
;
import
jakarta.validation.constraints.DecimalMin
;
import
jakarta.validation.constraints.Min
;
import
jakarta.validation.constraints.NotNull
;
import
jakarta.validation.constraints.Size
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
...
@@ -22,11 +28,17 @@ public class Product extends WspolnaNadklasa implements Serializable {
...
@@ -22,11 +28,17 @@ public class Product extends WspolnaNadklasa implements Serializable {
private
String
description
;
private
String
description
;
@NotNull
@DecimalMin
(
"0.01"
)
private
BigDecimal
price
;
private
BigDecimal
price
;
@Column
(
name
=
"product_name"
)
@Column
(
name
=
"product_name"
)
@NotNull
@Size
(
min
=
2
,
max
=
10
)
private
String
productName
;
private
String
productName
;
@DecimalMin
(
"0.00"
)
@DecimalMax
(
"0.50"
)
private
BigDecimal
vat
;
private
BigDecimal
vat
;
public
Product
()
{
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