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
b02f784f
Commit
b02f784f
authored
Sep 30, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
która godzina - pierwsze wersje
parent
48b106d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
2 deletions
+73
-2
DateTimeController.java
...ng/src/main/java/com/example/demo/DateTimeController.java
+58
-0
HelloController.java
...pring/src/main/java/com/example/demo/HelloController.java
+2
-2
show_time5.html
PC29-Spring/src/main/resources/templates/show_time5.html
+13
-0
No files found.
PC29-Spring/src/main/java/com/example/demo/DateTimeController.java
0 → 100644
View file @
b02f784f
package
com
.
example
.
demo
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Locale
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
@Controller
public
class
DateTimeController
{
@RequestMapping
(
"/time1"
)
@ResponseBody
public
LocalTime
time1
()
{
return
LocalTime
.
now
();
}
@RequestMapping
(
"/time2"
)
@ResponseBody
public
String
time2
()
{
return
LocalTime
.
now
().
toString
();
}
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/format/DateTimeFormatter.html#patterns
private
static
final
DateTimeFormatter
FORMAT_DATY
=
DateTimeFormatter
.
ofPattern
(
"EEEE, dd.MM.YYYY, 'godzina' HH:mm:ss"
,
new
Locale
(
"pl"
,
"PL"
));
@RequestMapping
(
path
=
"/time3"
,
produces
=
"text/plain"
)
@ResponseBody
public
String
time3
()
{
return
LocalDateTime
.
now
().
format
(
FORMAT_DATY
);
}
// Jak wysłać w odpowiedzi HTML?
// 1. Utworzyć bezpośrednio w kodzie Javy... - słabe
@RequestMapping
(
path
=
"/time4"
,
produces
=
"text/html"
)
@ResponseBody
public
String
time4
()
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
return
String
.
format
(
"<html><body><h1>Data i czas</h1>"
+
"<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>"
,
dt
.
toLocalTime
(),
dt
.
toLocalDate
(),
dt
.
format
(
FORMAT_DATY
));
}
@RequestMapping
(
"/time5"
)
public
String
time5
()
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
return
"show_time5.html"
;
}
}
PC29-Spring/src/main/java/com/example/demo/HelloController.java
View file @
b02f784f
...
...
@@ -30,8 +30,8 @@ public class HelloController {
// która wypisuje biężacy czas
@RequestMapping
(
"/ktora-godzina"
)
@ResponseBody
public
LocalTime
ktoraGodzina
()
{
return
LocalTime
.
now
();
public
String
ktoraGodzina
()
{
return
"Jest godzina "
+
LocalTime
.
now
();
}
}
PC29-Spring/src/main/resources/templates/show_time5.html
0 → 100644
View file @
b02f784f
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Która godzina 5
</title>
</head>
<body>
<h1>
Która godzina 5
</h1>
<p>
Zaraz powiem, która jest godzina...
</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