Commit 161646de by Patryk Czarnik

kalkulator - obsługa różnych działań

parent 856db191
......@@ -16,8 +16,15 @@ public class KalkulatorController {
}
@PostMapping
public String rozmowaPost(Integer liczba1, Integer liczba2, String operacja, Model model) {
Integer wynik = liczba1 + liczba2;
public String rozmowaPost(Long liczba1, Long liczba2, String operacja, Model model) {
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";
}
......
......@@ -21,8 +21,12 @@
<button>Oblicz</button>
</form>
<div class="wynik">
[[${wynik}]]
<div th:if="${wynik != null}" class="wynik">
<span th:text="${param.liczba1}">2</span>
<span th:text="${param.operacja}">+</span>
<span th:text="${param.liczba2}">3</span>
=
<strong th:text="${wynik}">5</strong>
</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment