Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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_20230928
Commits
4d81ff36
Commit
4d81ff36
authored
Oct 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przeniesienie adresu /products na poziom klasy
parent
a413d668
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+6
-4
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
4d81ff36
...
@@ -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.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
sklep.model.Product
;
import
sklep.model.Product
;
...
@@ -16,18 +17,19 @@ import sklep.repository.ProductRepository;
...
@@ -16,18 +17,19 @@ import sklep.repository.ProductRepository;
import
sklep.util.PhotoUtil
;
import
sklep.util.PhotoUtil
;
@Controller
@Controller
@RequestMapping
(
"/products"
)
public
class
ProductController
{
public
class
ProductController
{
@Autowired
@Autowired
private
ProductRepository
productRepository
;
private
ProductRepository
productRepository
;
@GetMapping
(
"/products"
)
@GetMapping
public
String
readAll
(
Model
model
)
{
public
String
readAll
(
Model
model
)
{
List
<
Product
>
products
=
productRepository
.
findAll
();
List
<
Product
>
products
=
productRepository
.
findAll
();
model
.
addAttribute
(
"products"
,
products
);
model
.
addAttribute
(
"products"
,
products
);
return
"products"
;
return
"products"
;
}
}
@GetMapping
(
"/
products/
{numer}"
)
@GetMapping
(
"/{numer}"
)
public
String
readOne
(
Model
model
,
@PathVariable
Integer
numer
)
{
public
String
readOne
(
Model
model
,
@PathVariable
Integer
numer
)
{
Optional
<
Product
>
product
=
productRepository
.
findById
(
numer
);
Optional
<
Product
>
product
=
productRepository
.
findById
(
numer
);
...
@@ -40,7 +42,7 @@ public class ProductController {
...
@@ -40,7 +42,7 @@ public class ProductController {
}
}
}
}
@GetMapping
(
"/
products/
szukaj"
)
@GetMapping
(
"/szukaj"
)
public
String
szukaj
(
Model
model
,
public
String
szukaj
(
Model
model
,
String
name
,
String
name
,
BigDecimal
min
,
BigDecimal
min
,
...
@@ -69,7 +71,7 @@ public class ProductController {
...
@@ -69,7 +71,7 @@ public class ProductController {
return
"wyszukiwarka2"
;
return
"wyszukiwarka2"
;
}
}
@GetMapping
(
path
=
"/
products/
{id}/photo"
,
produces
=
"image/jpeg"
)
@GetMapping
(
path
=
"/{id}/photo"
,
produces
=
"image/jpeg"
)
@ResponseBody
@ResponseBody
public
byte
[]
getPhoto
(
@PathVariable
(
"id"
)
Integer
productId
)
{
public
byte
[]
getPhoto
(
@PathVariable
(
"id"
)
Integer
productId
)
{
return
photoUtil
.
readBytes
(
productId
);
return
photoUtil
.
readBytes
(
productId
);
...
...
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