Commit fbeaa7b0 by Patryk Czarnik

@RequestMapping(path="/rozmowa", method=GET)

parent 634f9a9c
...@@ -3,17 +3,26 @@ package com.example.demo; ...@@ -3,17 +3,26 @@ 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 RozmowaController { public class RozmowaController {
@RequestMapping("/rozmowa") @RequestMapping(path="/rozmowa", method=RequestMethod.GET)
public String rozmowa() {
// w przypadku metody GET tylko wyświetlamy pusty formularz
return "rozmowa.html";
}
@RequestMapping(path="/rozmowa", method=RequestMethod.POST)
public String rozmowa(String imie, Model model) { public String rozmowa(String imie, Model model) {
// w przypadku metody POST pobieramy przysłane imię i umieszczamy powitanie na stronie
// (o ile imię zostało przysłane)
System.out.println("Przysłane imię: " + imie); System.out.println("Przysłane imię: " + imie);
if(imie != null && !imie.isEmpty()) { if(imie != null && !imie.isEmpty()) {
model.addAttribute("powitanie", "Witaj " + imie); model.addAttribute("powitanie", "Witaj " + imie);
} }
return "rozmowa.html"; return "rozmowa.html";
} }
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<body> <body>
<h1>Rozmowa ze Springiem</h1> <h1>Rozmowa ze Springiem</h1>
<form> <form method="post">
<label for="imie">Jak masz na imię?</label><br> <label for="imie">Jak masz na imię?</label><br>
<input type="text" name="imie" id="imie"><br> <input type="text" name="imie" id="imie"><br>
<button>OK</button> <button>OK</button>
......
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