Commit 3b8a00ea by Patryk Czarnik

rozmowa: rozdzielenie GET i POST

parent bd74485b
......@@ -3,13 +3,21 @@ 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 RozmowaController {
@RequestMapping("/rozmowa")
public String rozmowa(String imie, Model model) {
@RequestMapping(path="/rozmowa", method=RequestMethod.GET)
public String rozmowaGet() {
return "rozmowa.html";
}
@RequestMapping(path="/rozmowa", method=RequestMethod.POST)
public String rozmowaPost(String imie, Model model) {
if(imie != null && !imie.isBlank()) {
model.addAttribute("message", "Witaj " + imie);
}
return "rozmowa.html";
}
......
......@@ -8,13 +8,13 @@
<body>
<h1>Rozmowa ze Springiem</h1>
<form>
<form method="post">
<label for="imie">Jak masz na imię?</label><br>
<input id="imie" name="imie" type="text"><br>
<button>OK</button>
</form>
<div class="wynik" th:text="${message}">
<div class="wynik" th:text="${message}" th:if="${message != null}">
Lorem ipsum.
</div>
......
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