Difference Between th:text and th:value in Thymeleaf (#13854)
This commit is contained in:
parent
be8bdbb5ff
commit
2a670412e0
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Difference Between th:text and th:value in Thymeleaf</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1 th:text="${title} ?: 'Default title'"/>
|
||||
|
||||
<form th:action="@{/attributes}" method="post">
|
||||
<label>Email:
|
||||
<input name="email" type="email" th:value="${email}">
|
||||
</label>
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue