Commit fbeaa7b0 by Patryk Czarnik

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

parent 634f9a9c
......@@ -3,12 +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")
@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) {
// 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);
if(imie != null && !imie.isEmpty()) {
model.addAttribute("powitanie", "Witaj " + imie);
......
......@@ -8,7 +8,7 @@
<body>
<h1>Rozmowa ze Springiem</h1>
<form>
<form method="post">
<label for="imie">Jak masz na imię?</label><br>
<input type="text" name="imie" id="imie"><br>
<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