Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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_20230617
Commits
41cb081f
Commit
41cb081f
authored
Aug 19, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Klasa Ogloszenie i dostęp
parent
4025637e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
2 deletions
+124
-2
Ogloszenie.java
...taH2/src/main/java/com/example/demo/model/Ogloszenie.java
+72
-0
OgloszeniaRepository.java
...main/java/com/example/demo/repo/OgloszeniaRepository.java
+10
-0
ROgloszenia.java
...taH2/src/main/java/com/example/demo/rest/ROgloszenia.java
+32
-0
application.properties
PC51-SpringDataH2/src/main/resources/application.properties
+3
-1
index.html
PC51-SpringDataH2/src/main/resources/templates/index.html
+7
-1
No files found.
PC51-SpringDataH2/src/main/java/com/example/demo/model/Ogloszenie.java
0 → 100644
View file @
41cb081f
package
com
.
example
.
demo
.
model
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.GeneratedValue
;
import
jakarta.persistence.GenerationType
;
import
jakarta.persistence.Id
;
@Entity
public
class
Ogloszenie
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Long
id
;
private
String
tytul
;
private
BigDecimal
cena
;
private
LocalDateTime
dataWystawienia
;
public
Ogloszenie
()
{
}
public
Ogloszenie
(
Long
id
,
String
tytul
,
BigDecimal
cena
,
LocalDateTime
dataWystawienia
)
{
this
.
id
=
id
;
this
.
tytul
=
tytul
;
this
.
cena
=
cena
;
this
.
dataWystawienia
=
dataWystawienia
;
}
public
Ogloszenie
(
String
tytul
,
BigDecimal
cena
)
{
this
(
null
,
tytul
,
cena
,
LocalDateTime
.
now
());
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getTytul
()
{
return
tytul
;
}
public
void
setTytul
(
String
tytul
)
{
this
.
tytul
=
tytul
;
}
public
BigDecimal
getCena
()
{
return
cena
;
}
public
void
setCena
(
BigDecimal
cena
)
{
this
.
cena
=
cena
;
}
public
LocalDateTime
getDataWystawienia
()
{
return
dataWystawienia
;
}
public
void
setDataWystawienia
(
LocalDateTime
dataWystawienia
)
{
this
.
dataWystawienia
=
dataWystawienia
;
}
@Override
public
String
toString
()
{
return
"Ogloszenie [id="
+
id
+
", tytul="
+
tytul
+
", cena="
+
cena
+
", dataWystawienia="
+
dataWystawienia
+
"]"
;
}
}
PC51-SpringDataH2/src/main/java/com/example/demo/repo/OgloszeniaRepository.java
0 → 100644
View file @
41cb081f
package
com
.
example
.
demo
.
repo
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
com.example.demo.model.Ogloszenie
;
public
interface
OgloszeniaRepository
extends
JpaRepository
<
Ogloszenie
,
Long
>
{
}
\ No newline at end of file
PC51-SpringDataH2/src/main/java/com/example/demo/rest/ROgloszenia.java
0 → 100644
View file @
41cb081f
package
com
.
example
.
demo
.
rest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
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.RestController
;
import
org.springframework.web.server.ResponseStatusException
;
import
com.example.demo.model.Customer
;
import
com.example.demo.model.Ogloszenie
;
import
com.example.demo.repo.CustomerRepository
;
import
com.example.demo.repo.OgloszeniaRepository
;
@RestController
@RequestMapping
(
path
=
"/rest/ogloszenia"
,
produces
=
"application/json"
)
public
class
ROgloszenia
{
@Autowired
private
OgloszeniaRepository
ogloszeniaRepository
;
@GetMapping
public
Iterable
<
Ogloszenie
>
readAll
()
{
return
ogloszeniaRepository
.
findAll
();
}
@GetMapping
(
"/{id}"
)
public
Ogloszenie
readOne
(
@PathVariable
(
"id"
)
long
id
)
{
return
ogloszeniaRepository
.
findById
(
id
)
.
orElseThrow
(()
->
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
));
}
}
PC51-SpringDataH2/src/main/resources/application.properties
View file @
41cb081f
spring.datasource.url
=
jdbc:h2:mem:test
spring.h2.console.enabled
=
true
spring.h2.console.path
=
/h2
PC51-SpringDataH2/src/main/resources/templates/index.html
View file @
41cb081f
...
@@ -9,13 +9,19 @@
...
@@ -9,13 +9,19 @@
<h1>
Zabawy w H2
</h1>
<h1>
Zabawy w H2
</h1>
<form
id=
"init-form"
th:action=
"@{/init}"
>
<form
id=
"init-form"
th:action=
"@{/init}"
>
<button>
Zainicjuj bazę
</button>
<button>
Wgraj dane
</button>
</form>
<form
id=
"h2-console"
th:action=
"@{/h2}"
target=
"_blank"
>
<button>
Konsola H2
</button>
</form>
</form>
<h2>
Zapytania REST-owe
</h2>
<h2>
Zapytania REST-owe
</h2>
<ul>
<ul>
<li><a
th:href=
"@{/rest/customers}"
>
/rest/customers
</a></li>
<li><a
th:href=
"@{/rest/customers}"
>
/rest/customers
</a></li>
<li><a
th:href=
"@{/rest/customers/1}"
>
/rest/customers/1
</a></li>
<li><a
th:href=
"@{/rest/customers/1}"
>
/rest/customers/1
</a></li>
<li><a
th:href=
"@{/rest/ogloszenia}"
>
/rest/ogloszenia
</a></li>
<li><a
th:href=
"@{/rest/ogloszenia/1}"
>
/rest/ogloszenia/1
</a></li>
</ul>
</ul>
</body>
</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