Commit f68d8e1c by Patryk Czarnik

blog: dodawnaie tekstów do listy jako pole prywatne w kontrolerze

parent f770f388
package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -9,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/blog")
public class BlogController {
private List<String> teksty = new ArrayList<>();
@GetMapping
public String rozmowaGet() {
......@@ -18,8 +22,9 @@ public class BlogController {
@PostMapping
public String rozmowaPost(String tekst, Model model) {
if(tekst != null && !tekst.isBlank()) {
teksty.add(tekst);
}
model.addAttribute("teksty", teksty);
return "blog.html";
}
......
......@@ -16,7 +16,7 @@
<section>
<h2>Zapamiętane teksty:</h2>
<ul>
<li>przykładowy tekst</li>
<li th:each="tekst : ${teksty}" th:text="${tekst}">przykładowy tekst</li>
</ul>
</section>
......
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