Commit c9e6f119 by Patryk Czarnik

Adres URL wyciągnięty na poziom klasy

parent 795aff08
...@@ -5,18 +5,20 @@ import org.springframework.ui.Model; ...@@ -5,18 +5,20 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller @Controller
@RequestMapping("/kalkulator")
// Na poziomie klasy podany jest adres, pod którym działa kontroler, a metody wewnątrz tylko określają rodzaj zapytania.
// Gdyby w którejś metodzie też był podany adres, byłoby to traktowane jako dalszy ciąg adresu, np. /kalkulator/historia
public class Kalkulator { public class Kalkulator {
@GetMapping("/kalkulator") @GetMapping
public String kalkulatorGet() { public String kalkulatorGet() {
// Obsługa metody GET - tylko wyświetlenie pustego formularza // Obsługa metody GET - tylko wyświetlenie pustego formularza
return "kalkulator.html"; return "kalkulator.html";
} }
@PostMapping("/kalkulator") @PostMapping
public String kalkulatorPost(Model model, Integer liczba1, Integer liczba2, String operacja) { public String kalkulatorPost(Model model, Integer liczba1, Integer liczba2, String operacja) {
// Obsługa metody POST - zakładamy, że parametry zostały przekazane (a jeśli nie, to będzie wyjątek). // Obsługa metody POST - zakładamy, że parametry zostały przekazane (a jeśli nie, to będzie wyjątek).
Integer wynik = switch(operacja) { Integer wynik = switch(operacja) {
......
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