jeudi 26 décembre 2019

How to call a method in HTML(Thymeleaf, Spring, Java)?

i'm beginner with Thymeleaf, but i want know how to call a method in HTML with Thymeleaf. I'm using Spring Boot with Spring MVC.

I want create a Button with a name like "Edit" and the user will edit the post of the blog, but if i want do that i have to know what's the ID from object Postagem.

My current code HTML: (blog.html)

        <div th:each="postagem : ${postagens}">
            <div class="blog-post">
                <h2 class="blog-post-title" th:text="${postagem.titulo}"></h2>
                <p class="blog-post-meta">25 de dezembro de 2019 publicado por <a href="#">Vitor</a></p>
                <p th:text="${postagem.texto}"></p>
                <button type="submit" class="btn btn-link">Edit</button>
            </div>
            <!-- /.blog-post -->
        </div>

My current method in Java: (PostagemController.java)

@PostMapping("/blog")
public String test(Postagem postagem) {
    System.out.println("Postagem Id: " + postagem.getId());
    return "redirect:/painel";
}



Aucun commentaire:

Enregistrer un commentaire