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
7dbc0332
Commit
7dbc0332
authored
Oct 04, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drobne dopiski
parent
e9a247f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
2 deletions
+9
-2
DateTimeController.java
...ng/src/main/java/com/example/demo/DateTimeController.java
+1
-1
Kalkulator.java
PC29-Spring/src/main/java/com/example/demo/Kalkulator.java
+3
-1
ParametryController.java
...g/src/main/java/com/example/demo/ParametryController.java
+5
-0
No files found.
PC29-Spring/src/main/java/com/example/demo/DateTimeController.java
View file @
7dbc0332
...
@@ -40,7 +40,7 @@ public class DateTimeController {
...
@@ -40,7 +40,7 @@ public class DateTimeController {
// Jak wysłać w odpowiedzi HTML?
// Jak wysłać w odpowiedzi HTML?
// 1. Utworzyć bezpośrednio w kodzie Javy... - słabe
// 1. Utworzyć bezpośrednio w kodzie Javy... - słabe
@RequestMapping
(
path
=
"/time4"
,
produces
=
"text/html"
)
@RequestMapping
(
path
=
"/time4"
,
produces
=
"text/html"
)
@ResponseBody
@ResponseBody
public
String
time4
()
{
public
String
time4
()
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
LocalDateTime
dt
=
LocalDateTime
.
now
();
...
...
PC29-Spring/src/main/java/com/example/demo/Kalkulator.java
View file @
7dbc0332
...
@@ -15,8 +15,10 @@ public class Kalkulator {
...
@@ -15,8 +15,10 @@ public class Kalkulator {
return
"kalkulator.html"
;
return
"kalkulator.html"
;
}
}
// Spring automatycznie przekaże parametry zapytania (dane z formularza)
// do tej metody - wystarczy zadeklarować parametry o tej samej nazwie.
@PostMapping
@PostMapping
public
String
kalkulatorPost
(
Model
model
,
long
liczba1
,
l
ong
liczba2
,
String
operacja
)
{
public
String
kalkulatorPost
(
Model
model
,
Long
liczba1
,
L
ong
liczba2
,
String
operacja
)
{
long
wynik
=
switch
(
operacja
)
{
long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
...
...
PC29-Spring/src/main/java/com/example/demo/ParametryController.java
View file @
7dbc0332
...
@@ -39,4 +39,9 @@ public class ParametryController {
...
@@ -39,4 +39,9 @@ public class ParametryController {
return
(
tekst
+
"\n"
).
repeat
(
ileRazy
);
return
(
tekst
+
"\n"
).
repeat
(
ileRazy
);
}
}
// Parametry bez adnotacji są opcjonalne - w razie braku Spring wywoła metodę i wstawi nulla.
// Parametry z adnotacją @RequestParam są domyślnie obowiązkowe. Aby był opcjonalny,
// trzeba wpisać required=false (wtedy brak parametru = null)
// lub podać defaultValue.
}
}
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