Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
982953d6
Commit
982953d6
authored
Jul 15, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kalkulator - lepsza wersja
parent
cbbebbea
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
12 deletions
+29
-12
KalkulatorController.java
.../src/main/java/com/example/demo/KalkulatorController.java
+10
-2
kalkulator.html
PC25-Spring/src/main/resources/templates/kalkulator.html
+19
-10
No files found.
PC25-Spring/src/main/java/com/example/demo/KalkulatorController.java
View file @
982953d6
...
@@ -16,8 +16,16 @@ public class KalkulatorController {
...
@@ -16,8 +16,16 @@ public class KalkulatorController {
}
}
@PostMapping
@PostMapping
public
String
kalkulatorPost
(
Long
liczba1
,
Long
liczba2
,
Model
model
)
{
public
String
kalkulatorPost
(
Long
liczba1
,
Long
liczba2
,
String
operacja
,
Model
model
)
{
model
.
addAttribute
(
"wynik"
,
liczba1
+
liczba2
);
long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0
;
};
model
.
addAttribute
(
"wynik"
,
wynik
);
return
"kalkulator.html"
;
return
"kalkulator.html"
;
}
}
...
...
PC25-Spring/src/main/resources/templates/kalkulator.html
View file @
982953d6
...
@@ -2,23 +2,32 @@
...
@@ -2,23 +2,32 @@
<html
lang=
"pl"
xmlns:th=
"http://www.thymeleaf.org"
>
<html
lang=
"pl"
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
Rozmowa
</title>
<title>
Kalkulator
</title>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/styl.css}"
href=
"../static/styl.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/styl.css}"
href=
"../static/styl.css"
>
</head>
</head>
<body>
<body>
<h1>
Rozmowa ze Springiem
</h1>
<h1>
Kalkulator
</h1>
<form
method=
"post"
>
<form
method=
"post"
>
<label
for=
"liczba1"
>
Podaj pierwszą liczbę
</label><br>
<p>
Wprowadź liczby i wybierz działanie
</p>
<input
type=
"text"
name=
"liczba1"
id=
"liczba1"
><br>
<input
type=
"number"
name=
"liczba1"
id=
"liczba1"
th:value=
"${param.liczba1}"
>
<label
for=
"liczba2"
>
Podaj drugą liczbę
</label><br>
<select
name=
"operacja"
>
<input
type=
"text"
name=
"liczba2"
id=
"liczba2"
><br>
<option
value=
"+"
>
+
</option>
<button>
Dodaj
</button>
<option
value=
"-"
>
-
</option>
<option
value=
"*"
>
*
</option>
<option
value=
"/"
>
/
</option>
</select>
<input
type=
"number"
name=
"liczba2"
id=
"liczba2"
th:value=
"${param.liczba2}"
>
<button>
Oblicz
</button>
</form>
</form>
<div
class=
"wynik"
<div
th:if=
"${wynik != null}"
class=
"wynik"
>
th:if=
"${wynik != null}"
<span
th:text=
"${param.liczba1}"
>
2
</span>
th:text=
"${wynik}"
>
1234
</div>
<span
th:text=
"${param.operacja}"
>
+
</span>
<span
th:text=
"${param.liczba2}"
>
3
</span>
=
<strong
th:text=
"${wynik}"
>
5
</strong>
</div>
</body>
</body>
</html>
</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