Commit 0bbf0f9c by Patryk Czarnik

kalkulator GET - implementacja w jednej metodzie

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