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
c17065bb
Commit
c17065bb
authored
May 31, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edycja produktów - wersja bez walidacji
parent
b2ad6b14
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
1 deletions
+80
-1
BasketConfiguration.java
...pring/src/main/java/sklep/basket/BasketConfiguration.java
+1
-1
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+24
-0
SecurityConfig.java
...epSpring/src/main/java/sklep/security/SecurityConfig.java
+1
-0
product_form.jsp
...Spring/src/main/webapp/WEB-INF/templates/product_form.jsp
+54
-0
No files found.
PC37-SklepSpring/src/main/java/sklep/basket/BasketConfiguration.java
View file @
c17065bb
...
@@ -11,7 +11,7 @@ import jakarta.servlet.http.HttpSessionListener;
...
@@ -11,7 +11,7 @@ import jakarta.servlet.http.HttpSessionListener;
public
class
BasketConfiguration
{
public
class
BasketConfiguration
{
// Adnotacja Configuration powoduje, że:
// Adnotacja Configuration powoduje, że:
// - Spring tworzy obiekt tej klasy (BasketConfiguration)
// - Spring tworzy obiekt tej klasy (BasketConfiguration)
// - dla każdej meody oznaczonej @Bean uruchamia tę metodę, a jej wynik rejestruje jako bean
// - dla każdej me
t
ody oznaczonej @Bean uruchamia tę metodę, a jej wynik rejestruje jako bean
// - gdy typ wynikowy "znaczy dla Springa coś specjalnego", to Spring weźmie to pod uwagę,
// - gdy typ wynikowy "znaczy dla Springa coś specjalnego", to Spring weźmie to pod uwagę,
// właśnie w ten sposób często podaje się Springowi elementy konfiguracji
// właśnie w ten sposób często podaje się Springowi elementy konfiguracji
...
...
PC37-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
c17065bb
...
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
...
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
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.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.SessionAttribute
;
import
org.springframework.web.bind.annotation.SessionAttribute
;
...
@@ -80,6 +81,29 @@ public class ProductController {
...
@@ -80,6 +81,29 @@ public class ProductController {
return
"redirect:/products"
;
return
"redirect:/products"
;
}
}
@GetMapping
(
"/new"
)
public
String
nowyProdukt
()
{
return
"product_form"
;
}
@GetMapping
(
"/{id}/edit"
)
public
String
edytujProdukt
(
@PathVariable
int
id
,
Model
model
)
{
Optional
<
Product
>
product
=
productRepository
.
findById
(
id
);
if
(
product
.
isPresent
())
{
model
.
addAttribute
(
"product"
,
product
.
get
());
return
"product_form"
;
}
else
{
model
.
addAttribute
(
"product_id"
,
id
);
return
"missing_product"
;
}
}
@PostMapping
({
"/new"
,
"/{id}/edit"
})
public
String
zapiszProdukt
(
Product
product
)
{
productRepository
.
save
(
product
);
return
"product_form"
;
}
@GetMapping
(
produces
=
"text/plain"
)
@GetMapping
(
produces
=
"text/plain"
)
@ResponseBody
@ResponseBody
public
String
getProductsTxt
()
{
public
String
getProductsTxt
()
{
...
...
PC37-SklepSpring/src/main/java/sklep/security/SecurityConfig.java
View file @
c17065bb
...
@@ -12,6 +12,7 @@ public class SecurityConfig {
...
@@ -12,6 +12,7 @@ public class SecurityConfig {
@Bean
@Bean
SecurityFilterChain
configureHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
SecurityFilterChain
configureHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
httpSecurity
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
());
httpSecurity
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
());
httpSecurity
.
csrf
(
csrf
->
csrf
.
disable
());
return
httpSecurity
.
build
();
return
httpSecurity
.
build
();
}
}
...
...
PC37-SklepSpring/src/main/webapp/WEB-INF/templates/product_form.jsp
0 → 100644
View file @
c17065bb
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"jakarta.tags.core"
%
>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Edycja danych produktu
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/styl.css"
>
</head>
<body>
<h1>
Edycja produktu
</h1>
<form
id=
"product-form"
method=
"post"
>
<table
class=
"form"
>
<tr>
<td><label
for=
"productId"
>
Numer:
</label></td>
<td><input
id=
"productId"
name=
"id"
placeholder=
"brak"
type=
"number"
readonly=
"readonly"
value=
"${product.id}"
/></td>
</tr>
<tr>
<td><label
for=
"productName"
>
Nazwa towaru:
</label></td>
<td><input
id=
"productName"
name=
"productName"
placeholder=
"nazwa..."
type=
"text"
value=
"${product.productName}"
/>
</td>
</tr>
<tr>
<td><label
for=
"price"
>
Cena:
</label></td>
<td><input
id=
"price"
name=
"price"
placeholder=
"12.90"
title=
"tu wpisz cenę"
type=
"number"
step=
"0.01"
value=
"${product.price}"
/></td>
</tr>
<tr>
<td><label
for=
"vat"
>
Stawka VAT:
</label></td>
<td><input
id=
"vat"
name=
"vat"
placeholder=
"0.23"
title=
"tu wpisz vat"
type=
"number"
step=
"0.01"
value=
"${product.vat}"
/></td>
</tr>
<tr>
<td><label
for=
"description"
>
Opis:
</label></td>
<td><textarea
id=
"description"
name=
"description"
rows=
"10"
cols=
"120"
>
${product.description}
</textarea></td>
</tr>
<tr>
<td><button>
Zapisz
</button></td>
</tr>
</table>
</form>
<div
class=
"action"
>
<a
href=
"/products"
>
powrót do listy produktów
</a>
</div>
<div
class=
"action"
>
<a
href=
"/"
>
powrót do spisu treści
</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