From 2a670412e08c4c15072e665efe0f031036c0c2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Peterli=C4=87?= Date: Mon, 24 Apr 2023 04:57:14 +0200 Subject: [PATCH] Difference Between th:text and th:value in Thymeleaf (#13854) --- .../attributes/AttributeController.java | 30 +++++++++++++++++++ .../resources/templates/attributes/index.html | 19 ++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attributes/AttributeController.java create mode 100644 spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attributes/index.html diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attributes/AttributeController.java b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attributes/AttributeController.java new file mode 100644 index 0000000000..b7725fd992 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/attributes/AttributeController.java @@ -0,0 +1,30 @@ +package com.baeldung.thymeleaf.attributes; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/attributes") +public class AttributeController { + + private static final Logger logger = LoggerFactory.getLogger(AttributeController.class); + + @GetMapping + public String show(Model model) { + model.addAttribute("title", "Baeldung"); + model.addAttribute("email", "default@example.com"); + return "attributes/index"; + } + + @PostMapping + public String submit(String email) { + logger.info("Email: {}", email); + return "redirect:attributes"; + } + +} diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attributes/index.html b/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attributes/index.html new file mode 100644 index 0000000000..ed55b61a8a --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/resources/templates/attributes/index.html @@ -0,0 +1,19 @@ + + + + + Difference Between th:text and th:value in Thymeleaf + + + +

+ +
+ + +
+ + + \ No newline at end of file