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
a1849e28
Commit
a1849e28
authored
May 25, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thymeleaf - wersja bardzo początkowa
parent
22e55198
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
TimeController.java
...Spring/src/main/java/org/example/demo/TimeController.java
+11
-2
szablon_czasu_5.html
...-Spring/src/main/resources/templates/szablon_czasu_5.html
+11
-0
No files found.
PC35-Spring/src/main/java/org/example/demo/TimeController.java
View file @
a1849e28
...
...
@@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter;
import
java.util.Locale
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
...
@@ -27,7 +28,7 @@ public class TimeController {
}
// Gdy metoda zwraca String i posiada adnotację @ResponseBody, to odsyłany jest tekst.
// Domyślnie content-type to jest text/plain, ale jeśli przeglądarka żąda html, to Spring zwróci to oznaczone typem text/html
// Aby wymusić wysłanie odpowiedniego nagłówka Content-Type, możemy dopisać parametr do adnotacji GetMapping lub RequestMapping
// Aby wymusić wysłanie odpowiedniego nagłówka Content-Type, możemy dopisać parametr
produces
do adnotacji GetMapping lub RequestMapping
private
static
final
DateTimeFormatter
FORMAT_DATY
=
DateTimeFormatter
.
ofPattern
(
"EEEE, dd.MM.yyyy, 'godzina' HH:mm:ss"
,
Locale
.
of
(
"pl"
,
"PL"
));
...
...
@@ -51,8 +52,16 @@ public class TimeController {
<p>Teraz jest godzina <strong style='color:purple'>%s</strong></p>
<p>Dzisiejsza data: <strong style='color:blue'>%s</strong></p>
<p style='color: green'>%s</p>
</body></html>"""
,
</body></html>
"""
,
dt
.
toLocalTime
(),
dt
.
toLocalDate
(),
dt
.
format
(
FORMAT_DATY
));
}
@GetMapping
(
"/time5"
)
public
String
time5
(
Model
model
)
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
model
.
addAttribute
(
"czas"
,
dt
);
return
"szablon_czasu_5.html"
;
}
}
PC35-Spring/src/main/resources/templates/szablon_czasu_5.html
0 → 100644
View file @
a1849e28
<!DOCTYPE html>
<html>
<head>
<title>
Która godzina v5
</title>
</head>
<body>
<h1>
Szablon czasu 5
</h1>
<p>
Zaraz powiem, która godzina.
</p>
<p>
Bieżący czas to [[${czas}]].
</p>
</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