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
5bffc4d1
Commit
5bffc4d1
authored
Oct 04, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alternatywne produkty - by_price
parent
33db460e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletions
+16
-1
AlternatywneProdukty2.java
...src/main/java/sklep/controller/AlternatywneProdukty2.java
+15
-0
index.jsp
PC30-SklepSpring/src/main/webapp/WEB-INF/templates/index.jsp
+1
-1
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/AlternatywneProdukty2.java
View file @
5bffc4d1
package
sklep
.
controller
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
javax.persistence.EntityManager
;
...
...
@@ -11,6 +12,7 @@ import org.springframework.ui.Model;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
sklep.model.Product
;
...
...
@@ -35,4 +37,17 @@ public class AlternatywneProdukty2 {
return
"product"
;
}
@GetMapping
(
"/by_price"
)
public
String
byPrice
(
Model
model
,
@RequestParam
(
defaultValue
=
"0"
)
BigDecimal
min
,
@RequestParam
(
defaultValue
=
"999999999"
)
BigDecimal
max
)
{
String
ql
=
"SELECT p FROM Product p WHERE p.price BETWEEN :min AND :max ORDER BY p.productId"
;
TypedQuery
<
Product
>
query
=
em
.
createQuery
(
ql
,
Product
.
class
);
query
.
setParameter
(
"min"
,
min
);
query
.
setParameter
(
"max"
,
max
);
List
<
Product
>
products
=
query
.
getResultList
();
model
.
addAttribute
(
"products"
,
products
);
return
"products"
;
}
}
PC30-SklepSpring/src/main/webapp/WEB-INF/templates/index.jsp
View file @
5bffc4d1
...
...
@@ -45,7 +45,7 @@
<li><a
href=
"/alt1/products"
>
Dostęp JDBC
</a>
(wstrzykiwanie DataSource)
</li>
<li><a
href=
"/alt2/products"
>
Dostęp Hibernate/JPA
</a>
(wstrzykiwanie EntityManager)
</li>
<li><a
href=
"/alt2/products/1"
>
jeden produkt
</a></li>
<li><a
href=
"/alt2/
products/
by_price?min=1000&max=2900"
>
by price
</a></li>
<li><a
href=
"/alt2/by_price?min=1000&max=2900"
>
by price
</a></li>
</ul>
</body>
...
...
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