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 @@ + + +
+ +