Commit 8ccd7604 by Patryk Czarnik

oddzielnie GET i POST

parent b0360931
...@@ -3,12 +3,18 @@ package com.example.demo; ...@@ -3,12 +3,18 @@ package com.example.demo;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller @Controller
public class KalkulatorController { public class KalkulatorController {
@RequestMapping("/kalkulator") @RequestMapping(path="/kalkulator", method=RequestMethod.GET)
public String dzialaj(Long liczba1, Long liczba2, String operacja, Model model) { public String kalkulatorGet() {
return "kalkulator.html";
}
@RequestMapping(path="/kalkulator", method=RequestMethod.POST)
public String kalkulatorPost(Long liczba1, Long liczba2, String operacja, Model model) {
if(liczba1 != null && liczba2 != null && operacja != null) { if(liczba1 != null && liczba2 != null && operacja != null) {
Long wynik = switch(operacja) { Long wynik = switch(operacja) {
case "+" -> liczba1 + liczba2; case "+" -> liczba1 + liczba2;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<body> <body>
<h1>Kalkulator</h1> <h1>Kalkulator</h1>
<form class="kalkulator"> <form method="post" class="kalkulator">
<input type="number" name="liczba1" th:value="${param.liczba1}"> <input type="number" name="liczba1" th:value="${param.liczba1}">
<select name="operacja"> <select name="operacja">
<option value="+">+</option> <option value="+">+</option>
......
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