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
d130c3fb
Commit
d130c3fb
authored
Oct 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Odczyt produktów - pierwsza wersja z JpaRepository
parent
4c2ecab5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
4 deletions
+86
-4
pom.xml
PC30-SklepSpring/pom.xml
+8
-3
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+25
-0
ProductRepository.java
...ing/src/main/java/sklep/repository/ProductRepository.java
+9
-0
index.jsp
PC30-SklepSpring/src/main/webapp/index.jsp
+1
-1
products.jsp
PC30-SklepSpring/src/main/webapp/products.jsp
+43
-0
No files found.
PC30-SklepSpring/pom.xml
View file @
d130c3fb
<?xml version="1.0" encoding="UTF-8"?>
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
3.1.5
</version>
<version>
3.1.5
</version>
<relativePath/>
<!-- lookup parent from repository -->
<relativePath
/>
<!-- lookup parent from repository -->
</parent>
</parent>
<groupId>
pl.alx.kjava
</groupId>
<groupId>
pl.alx.kjava
</groupId>
<artifactId>
PC30-SklepSpring
</artifactId>
<artifactId>
PC30-SklepSpring
</artifactId>
...
@@ -65,6 +66,10 @@
...
@@ -65,6 +66,10 @@
<groupId>
jakarta.servlet.jsp.jstl
</groupId>
<groupId>
jakarta.servlet.jsp.jstl
</groupId>
<artifactId>
jakarta.servlet.jsp.jstl-api
</artifactId>
<artifactId>
jakarta.servlet.jsp.jstl-api
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.glassfish.web
</groupId>
<artifactId>
jakarta.servlet.jsp.jstl
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
0 → 100644
View file @
d130c3fb
package
sklep
.
controller
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
sklep.model.Product
;
import
sklep.repository.ProductRepository
;
@Controller
public
class
ProductController
{
@Autowired
private
ProductRepository
productRepository
;
@GetMapping
(
"/products"
)
public
String
readAll
(
Model
model
)
{
List
<
Product
>
products
=
productRepository
.
findAll
();
model
.
addAttribute
(
"products"
,
products
);
return
"products.jsp"
;
}
}
PC30-SklepSpring/src/main/java/sklep/repository/ProductRepository.java
0 → 100644
View file @
d130c3fb
package
sklep
.
repository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
sklep.model.Product
;
public
interface
ProductRepository
extends
JpaRepository
<
Product
,
Integer
>
{
}
PC30-SklepSpring/src/main/webapp/index.jsp
View file @
d130c3fb
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
Aplikacja Sklep Spring
</title>
<title>
Aplikacja Sklep Spring
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../..
/styl.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/styl.css"
>
</head>
</head>
<body>
<body>
<h1>
Spis treści
</h1>
<h1>
Spis treści
</h1>
...
...
PC30-SklepSpring/src/main/webapp/products.jsp
0 → 100644
View file @
d130c3fb
<
%@
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>
Katalog towarów
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/styl.css"
/>
</head>
<body>
<c:if
test=
"${not empty basket and not empty basket.elements}"
>
<div
class=
"basket"
>
<h4>
Koszyk
</h4>
<ul>
<c:forEach
var=
"p"
items=
"${basket.elements}"
>
<li>
${p.productName}: ${p.quantity} × ${p.price} =
<b>
${p.value}
</b></li>
</c:forEach>
</ul>
<p>
Wartość koszyka: ${basket.totalValue}
</p>
</div>
</c:if>
<h1>
Wszystkie produkty
</h1>
<c:forEach
var=
"product"
items=
"${products}"
>
<div
class=
"product"
>
<img
class=
"photo"
src=
"/products/${product.productId}/photo"
alt=
""
/>
<p>
Towar
<a
href=
"/products/${product.productId}"
class=
"product-name"
>
${product.productName}
</a></p>
<p>
Cena:
<span
class=
"product-price"
>
${product.price}
</span></p>
<p
class=
"product-description"
>
${product.description}
</p>
<div
class=
"action"
><a
href=
"/products/${product.productId}/edit"
>
Edytuj
</a></div>
<div
class=
"action"
><a
href=
"/products/${product.productId}/add-to-basket"
>
Dodaj do koszyka
</a></div>
</div>
</c:forEach>
<div><a
href=
"/products/new"
>
Dodaj nowy produkt
</a></div>
<div><a
href=
"/"
>
Wróć na stronę główną
</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