Commit 0bbf0f9c by Patryk Czarnik

kalkulator GET - implementacja w jednej metodzie

parent 65d20924
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class KalkulatorController {
@RequestMapping("/kalkulator")
public String dzialaj() {
public String dzialaj(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);
}
return "kalkulator.html";
}
......
......@@ -22,7 +22,7 @@
</form>
<div class="wynik">
TUTAJ COŚ NAPISZ
[[${wynik}]]
</div>
</body>
......
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