Commit 7dbc0332 by Patryk Czarnik

drobne dopiski

parent e9a247f0
......@@ -40,7 +40,7 @@ public class DateTimeController {
// Jak wysłać w odpowiedzi HTML?
// 1. Utworzyć bezpośrednio w kodzie Javy... - słabe
@RequestMapping(path = "/time4", produces = "text/html")
@RequestMapping(path="/time4", produces="text/html")
@ResponseBody
public String time4() {
LocalDateTime dt = LocalDateTime.now();
......
......@@ -15,8 +15,10 @@ public class Kalkulator {
return "kalkulator.html";
}
// Spring automatycznie przekaże parametry zapytania (dane z formularza)
// do tej metody - wystarczy zadeklarować parametry o tej samej nazwie.
@PostMapping
public String kalkulatorPost(Model model, long liczba1, long liczba2, String operacja) {
public String kalkulatorPost(Model model, Long liczba1, Long liczba2, String operacja) {
long wynik = switch(operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
......
......@@ -39,4 +39,9 @@ public class ParametryController {
return (tekst + "\n").repeat(ileRazy);
}
// Parametry bez adnotacji są opcjonalne - w razie braku Spring wywoła metodę i wstawi nulla.
// Parametry z adnotacją @RequestParam są domyślnie obowiązkowe. Aby był opcjonalny,
// trzeba wpisać required=false (wtedy brak parametru = null)
// lub podać defaultValue.
}
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