Commit 7e656505 by Patryk Czarnik

kalkulatorek - obsługa parametrów jak w serwletach

parent 8e78231b
package com.example.demo; package com.example.demo;
import javax.servlet.http.HttpServletRequest;
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 Kalkulatorek { public class Kalkulatorek {
@RequestMapping("/kalkulatorek") @RequestMapping("/kalkulatorek")
public String dzialaj() { public String dzialaj(Model model, HttpServletRequest request) {
String p1 = request.getParameter("liczba1");
String p2 = request.getParameter("liczba2");
if(p1 != null && p2 != null) {
int wynik = Integer.parseInt(p1) + Integer.parseInt(p2);
model.addAttribute("wynik", wynik);
}
return "kalkulatorek.html"; return "kalkulatorek.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