Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
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_weekendowa_20221008
Commits
cd280f79
Commit
cd280f79
authored
Nov 13, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wydzielenie metody oblicz
parent
09bcd4a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
Kalkulator.java
PC26-Spring/src/main/java/com/example/demo/Kalkulator.java
+12
-8
kalkulator.html
PC26-Spring/src/main/resources/templates/kalkulator.html
+3
-0
No files found.
PC26-Spring/src/main/java/com/example/demo/Kalkulator.java
View file @
cd280f79
...
...
@@ -19,18 +19,22 @@ public class Kalkulator {
}
@PostMapping
public
String
kalkulatorPost
(
Model
model
,
Integer
liczba1
,
Integer
liczba2
,
String
operacja
)
{
public
String
kalkulatorPost
(
Model
model
,
Long
liczba1
,
Long
liczba2
,
String
operacja
)
{
// Obsługa metody POST - zakładamy, że parametry zostały przekazane (a jeśli nie, to będzie wyjątek).
Integer
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0
;
};
long
wynik
=
oblicz
(
liczba1
,
liczba2
,
operacja
);
model
.
addAttribute
(
"wynik"
,
wynik
);
return
"kalkulator.html"
;
}
long
oblicz
(
long
liczba1
,
long
liczba2
,
String
operacja
)
{
switch
(
operacja
)
{
case
"+"
:
return
liczba1
+
liczba2
;
case
"-"
:
return
liczba1
-
liczba2
;
case
"*"
:
return
liczba1
*
liczba2
;
case
"/"
:
return
liczba1
/
liczba2
;
default
:
return
0
;
}
}
}
PC26-Spring/src/main/resources/templates/kalkulator.html
View file @
cd280f79
...
...
@@ -11,6 +11,9 @@
<form
class=
"kalkulator"
method=
"post"
>
<input
type=
"number"
name=
"liczba1"
th:value=
"${param.liczba1}"
>
<!--/* Opis, jak zautomatyzować działanie select/option w Thymeleaf, ale jakoś nie umiem tu zastosować:
https://www.baeldung.com/thymeleaf-select-option
*/-->
<select
name=
"operacja"
>
<option
value=
"+"
>
+
</option>
<option
value=
"-"
>
-
</option>
...
...
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