Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_3
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_mszczonow_3
Commits
43f23650
Commit
43f23650
authored
Jul 25, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oddzielnie GET i POST
parent
6f4ffb0e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
KalkulatorController.java
src/main/java/alx/kalkulator/KalkulatorController.java
+16
-11
kalkulator.html
src/main/resources/templates/kalkulator.html
+1
-1
No files found.
src/main/java/alx/kalkulator/KalkulatorController.java
View file @
43f23650
...
...
@@ -2,23 +2,28 @@ package alx.kalkulator;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
@Controller
public
class
KalkulatorController
{
@GetMapping
(
"/kalkulator"
)
public
String
kalkulatorGet
()
{
return
"kalkulator.html"
;
}
@
Reque
stMapping
(
"/kalkulator"
)
@
Po
stMapping
(
"/kalkulator"
)
public
String
kalkulator
(
Long
liczba1
,
Long
liczba2
,
String
operacja
,
Model
model
)
{
if
(
liczba1
!=
null
&&
liczba2
!=
null
&&
operacja
!=
null
)
{
Long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0L
;
};
model
.
addAttribute
(
"wynik"
,
wynik
);
}
Long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0L
;
};
model
.
addAttribute
(
"wynik"
,
wynik
);
return
"kalkulator.html"
;
}
}
src/main/resources/templates/kalkulator.html
View file @
43f23650
...
...
@@ -8,7 +8,7 @@
<body>
<h1>
Kalkulator
</h1>
<form
method=
"
ge
t"
class=
"kalkulator"
>
<form
method=
"
pos
t"
class=
"kalkulator"
>
<input
type=
"number"
name=
"liczba1"
th:value=
"${param.liczba1}"
>
<select
name=
"operacja"
>
<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