Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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_dzienna_15_09
Commits
a0d112e1
Commit
a0d112e1
authored
Oct 05, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edycja danych klienta
parent
55de9f88
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
0 deletions
+159
-0
CustomerController.java
...ng/src/main/java/sklep/controller/CustomerController.java
+79
-0
CustomerRepository.java
...ng/src/main/java/sklep/repository/CustomerRepository.java
+11
-0
OrderRepository.java
...pring/src/main/java/sklep/repository/OrderRepository.java
+11
-0
customer_form.jsp
...pring/src/main/webapp/WEB-INF/templates/customer_form.jsp
+58
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/CustomerController.java
0 → 100644
View file @
a0d112e1
package
sklep
.
controller
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.validation.Valid
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.server.ResponseStatusException
;
import
sklep.model.Customer
;
import
sklep.repository.CustomerRepository
;
@Controller
@RequestMapping
(
"/customers"
)
public
class
CustomerController
{
@Autowired
private
CustomerRepository
customerRepository
;
@GetMapping
public
String
listaKlientow
(
Model
model
)
{
List
<
Customer
>
customers
=
customerRepository
.
findAll
();
model
.
addAttribute
(
"customers"
,
customers
);
return
"customers"
;
}
@GetMapping
(
"/{email}"
)
public
String
jedenKlient
(
Model
model
,
@PathVariable
(
"email"
)
String
email
)
{
Optional
<
Customer
>
customer
=
customerRepository
.
findById
(
email
);
if
(
customer
.
isPresent
())
{
model
.
addAttribute
(
"customer"
,
customer
.
get
());
return
"customer"
;
}
else
{
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
"Nie ma klienta o mailu "
+
email
);
}
}
@GetMapping
(
"/new"
)
public
String
nowy
(
@ModelAttribute
Customer
customer
)
{
return
"customer_form"
;
}
@GetMapping
(
"/{email}/edit"
)
public
String
edytuj
(
Model
model
,
@PathVariable
(
"email"
)
String
email
)
{
Optional
<
Customer
>
customer
=
customerRepository
.
findById
(
email
);
if
(
customer
.
isPresent
())
{
model
.
addAttribute
(
"customer"
,
customer
.
get
());
return
"customer_form"
;
}
else
{
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
"Nie ma klienta o mailu "
+
email
);
}
}
@PostMapping
({
"/new"
,
"/{email}/edit"
})
public
String
zapisz
(
Model
model
,
@ModelAttribute
@Valid
Customer
customer
,
BindingResult
bindingResult
)
{
if
(
bindingResult
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
bindingResult
.
getAllErrors
());
return
"customer_form"
;
}
else
{
customerRepository
.
save
(
customer
);
// return "redirect:/customers";
return
"customer_form"
;
}
}
}
PC30-SklepSpring/src/main/java/sklep/repository/CustomerRepository.java
0 → 100644
View file @
a0d112e1
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
sklep.model.Customer
;
@Repository
public
interface
CustomerRepository
extends
JpaRepository
<
Customer
,
String
>
{
}
PC30-SklepSpring/src/main/java/sklep/repository/OrderRepository.java
0 → 100644
View file @
a0d112e1
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
sklep.model.Order
;
@Repository
public
interface
OrderRepository
extends
JpaRepository
<
Order
,
Integer
>
{
}
PC30-SklepSpring/src/main/webapp/WEB-INF/templates/customer_form.jsp
0 → 100644
View file @
a0d112e1
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"http://java.sun.com/jsp/jstl/core"
%
>
<
%@
taglib
prefix=
"s"
uri=
"http://www.springframework.org/tags"
%
>
<
%@
taglib
prefix=
"f"
uri=
"http://www.springframework.org/tags/form"
%
>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Edycja danych klienta
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/styl.css"
/>
</head>
<body>
<h1>
Edycja danych klienta
</h1>
<f:form
id=
"product-form"
method=
"post"
modelAttribute=
"customer"
>
<table
class=
"form-tab"
>
<tr>
<td><f:label
path=
"customerEmail"
>
Email:
</f:label></td>
<td><f:input
path=
"customerEmail"
type=
"email"
/>
<f:errors
path=
"customerEmail"
cssClass=
"form-error"
element=
"div"
/>
</td>
</tr>
<tr>
<td><f:label
path=
"customerName"
>
Nazwa / imię i nazwisko:
</f:label></td>
<td><f:input
path=
"customerName"
placeholder=
"Ala Kowalska"
type=
"text"
/>
<f:errors
path=
"customerName"
cssClass=
"form-error"
element=
"div"
/>
</td>
</tr>
<tr>
<td><f:label
path=
"phoneNumber"
>
Telefon:
</f:label></td>
<td><f:input
path=
"phoneNumber"
placeholder=
"123123123"
type=
"text"
/>
<f:errors
path=
"phoneNumber"
cssClass=
"form-error"
element=
"div"
/>
</td>
</tr>
<tr>
<td><f:label
path=
"address"
>
Adres:
</f:label></td>
<td><f:textarea
path=
"address"
rows=
"2"
cols=
"120"
/></td>
</tr>
<tr>
<td><f:label
path=
"postalCode"
>
Kod pocztowy:
</f:label></td>
<td><f:input
path=
"postalCode"
placeholder=
"12-345"
type=
"text"
/>
<f:errors
path=
"postalCode"
cssClass=
"form-error"
element=
"div"
/>
</td>
</tr>
<tr>
<td><f:label
path=
"city"
>
Miasto:
</f:label></td>
<td><f:input
path=
"city"
placeholder=
"Kraków"
type=
"text"
/>
<f:errors
path=
"city"
cssClass=
"form-error"
element=
"div"
/>
</td>
</tr>
<tr>
<td><f:button>
Zapisz
</f:button></td>
</tr>
</table>
</f:form>
</body>
</html>
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