i'm newby in Spring-boot i tried to display java object in form validation
but i can't see the élément in result page
and in result page this is what i got:
result [submision 0]it can't updating the HTML elements dynamially
@Controller
public class HomeController {
@RequestMapping("/")
public String Hello(Model model) {
model.addAttribute("fd", new User());
return "index";
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String FormSubmit(User user) {
return "result";
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>home page</title>
</head>
<body>
<p>entry your data</p>
<form action="/create" method="POST" th:object="${fd}">
<p>full name : <input type="text" th:filed="${fd.fullname}"></p><br>
<p> age :<input type="text" th:filed="${fd.age}"></p><br>
<p><input type="submit" value="Submit" /> <input type="reset" value="rest"></p>
</form>
</body>
</html>
///////////////////////RESULTHTML/////////////
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>result page</title>
</head>
<body>
<h1>result submision<h1>
<p> <span th:text="${user.fullname}"></span></p>
<p> <span th:text="${user.age}"></span></p>
</body>
</html>
CodePudding user response:
use
ModelAndView mav = new ModelAndView("result");
mav.addObject("user", user);
return mav;
for more please refer : https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html
CodePudding user response:
use
ModelAndView mav = new ModelAndView("result");
mav.addObject("user", user);
return mav;
for more please refer : https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html