Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
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
alx_java2b_20250412
Commits
dfb125f7
Commit
dfb125f7
authored
May 31, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strony dot. Customer
parent
74c23399
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
223 additions
and
0 deletions
+223
-0
CustomerController.java
...ng/src/main/java/sklep/controller/CustomerController.java
+79
-0
CustomerRepository.java
...ng/src/main/java/sklep/repository/CustomerRepository.java
+7
-0
OrderRepository.java
...pring/src/main/java/sklep/repository/OrderRepository.java
+8
-0
customer.jsp
...klepSpring/src/main/webapp/WEB-INF/templates/customer.jsp
+27
-0
customer_form.jsp
...pring/src/main/webapp/WEB-INF/templates/customer_form.jsp
+60
-0
customers.jsp
...lepSpring/src/main/webapp/WEB-INF/templates/customers.jsp
+42
-0
No files found.
PC37-SklepSpring/src/main/java/sklep/controller/CustomerController.java
0 → 100644
View file @
dfb125f7
package
sklep
.
controller
;
import
java.util.List
;
import
java.util.Optional
;
import
jakarta.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"
;
}
}
}
PC37-SklepSpring/src/main/java/sklep/repository/CustomerRepository.java
0 → 100644
View file @
dfb125f7
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
sklep.model.Customer
;
public
interface
CustomerRepository
extends
JpaRepository
<
Customer
,
String
>
{
}
PC37-SklepSpring/src/main/java/sklep/repository/OrderRepository.java
0 → 100644
View file @
dfb125f7
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
sklep.model.Order
;
public
interface
OrderRepository
extends
JpaRepository
<
Order
,
Integer
>
{
}
PC37-SklepSpring/src/main/webapp/WEB-INF/templates/customer.jsp
0 → 100644
View file @
dfb125f7
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"jakarta.tags.core"
%
>
<
%@
taglib
prefix=
"s"
uri=
"http://www.springframework.org/tags"
%
>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Klient ${customer.customerName}
</title>
<c:url
var=
"style_url"
value=
"/styl.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"${style_url}"
/>
</head>
<body>
<h1>
Klient ${customer.customerName}
</h1>
<table
class=
"data-table"
>
<tr><th>
Email:
</th><td>
${customer.customerEmail}
</td></tr>
<tr><th>
Nazwa:
</th><td>
${customer.customerName}
</td></tr>
<tr><th>
Numer tel:
</th><td>
${customer.phoneNumber}
</td></tr>
<tr><th>
Adres:
</th><td>
${customer.address}
</td></tr>
<tr><th>
Miasto:
</th><td>
${customer.postalCode} ${customer.city}
</td></tr>
</table>
<c:url
var=
"adres_do_edycji"
value=
"/customers/${customer.customerEmail}/edit"
/>
<div
class=
"action"
><a
href=
"${adres_edycji}"
>
Edytuj
</a></div>
</body>
</html>
PC37-SklepSpring/src/main/webapp/WEB-INF/templates/customer_form.jsp
0 → 100644
View file @
dfb125f7
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"jakarta.tags.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>
<c:url
var=
"style_url"
value=
"/styl.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"${style_url}"
/>
</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=
"Jan Kowalski"
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>
<div><a
href=
"${pageContext.request.contextPath}/customers"
>
powrót do listy klientów
</a></div>
</body>
</html>
PC37-SklepSpring/src/main/webapp/WEB-INF/templates/customers.jsp
0 → 100644
View file @
dfb125f7
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"jakarta.tags.core"
%
>
<
%@
taglib
prefix=
"s"
uri=
"http://www.springframework.org/tags"
%
>
<!DOCTYPE html>
<
%
--
W
tym
pliku
u
ż
ywam
tag
ó
w
c:url
do
generowania
adres
ó
w
,
kt
ó
re
s
ą
poprawne
niezale
ż
nie
od
miejsca
zdeployowania
aplikacji
.
Oboj
ę
tnie
,
czy
aplikacja
dzia
ł
abezpo
ś
rednio
pod
adresem
localhost:8080
/
,
czy
w
jakim
ś
podkatalogu
(
ma
niepusty
"
context-path
"),
-
adresy
s
ą
odpowiednio
poprawiane
.
Jest
to
jednak
nieco
pracoch
ł
onne
w
zapisie
,
dlatego
jest
to
tylko
w
tym
jednym
pliku
.
--
%
>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Lista klientów
</title>
<c:url
var=
"style_url"
value=
"/styl.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"${style_url}"
/>
</head>
<body>
<h1>
Lista klientów
</h1>
<table
class=
"data-table"
>
<tr><th>
Email
</th><th>
Nazwa
</th><th>
Telefon
</th><th>
Adres
</th><th>
Miasto
</th><th/></tr>
<c:forEach
var=
"customer"
items=
"${customers}"
>
<c:url
var=
"adr"
value=
"/customers/${customer.customerEmail}"
/>
<tr>
<td><a
href=
"${adr}"
>
${customer.customerEmail}
</a></td>
<td>
${customer.customerName}
</td>
<td>
${customer.phoneNumber}
</td>
<td>
${customer.address}
</td>
<td>
${customer.postalCode} ${customer.city}
</td>
<td>
<c:url
var=
"adres_do_edycji"
value=
"/customers/${customer.customerEmail}/edit"
/>
<div
class=
"action"
><a
href=
"${adres_do_edycji}"
>
Edytuj
</a></div>
</td>
</tr>
</c:forEach>
</table>
<c:url
var=
"adres_new"
value=
"/customers/new"
/>
<div
class=
"action"
><a
href=
"${adres_new}"
>
Dodaj nowego klienta
</a></div>
</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