Commit 7420a799 by Patryk Czarnik

Przykład Rozmowa

parent 4a18f33d
package org.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import jakarta.servlet.http.HttpServletRequest;
......
package org.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class RozmowaController {
@GetMapping("/rozmowa")
public String dzialaj(String imie, Model model) {
if(imie != null && !imie.isEmpty()) {
String powitanie = "Witaj " + imie;
model.addAttribute("powitanie", powitanie);
}
return "rozmowa.html";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Rozmowa</title>
<link rel="stylesheet" type="text/css" th:href="@{/styl.css}">
</head>
<body>
<form>
<label for="imie">Jak masz na imię?</label><br>
<input id="imie" name="imie" type="text"><br>
<button>Wyślij</button>
</form>
<div class="wynik" th:if="${powitanie != null}" th:text="${powitanie}">Heloł</div>
</body>
</html>
\ No newline at end of file
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