Commit 8ccd7604 by Patryk Czarnik

oddzielnie GET i POST

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