Commit 161646de by Patryk Czarnik

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

parent 856db191
...@@ -16,8 +16,15 @@ public class KalkulatorController { ...@@ -16,8 +16,15 @@ public class KalkulatorController {
} }
@PostMapping @PostMapping
public String rozmowaPost(Integer liczba1, Integer liczba2, String operacja, Model model) { public String rozmowaPost(Long liczba1, Long liczba2, String operacja, Model model) {
Integer wynik = liczba1 + liczba2; Long wynik = switch(operacja) {
case "+"-> liczba1 + liczba2;
case "-"-> liczba1 - liczba2;
case "*"-> liczba1 * liczba2;
case "/"-> liczba1 / liczba2;
default -> 0L;
};
model.addAttribute("wynik", wynik); model.addAttribute("wynik", wynik);
return "kalkulator.html"; return "kalkulator.html";
} }
......
...@@ -21,8 +21,12 @@ ...@@ -21,8 +21,12 @@
<button>Oblicz</button> <button>Oblicz</button>
</form> </form>
<div class="wynik"> <div th:if="${wynik != null}" class="wynik">
[[${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> </div>
</body> </body>
</html> </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