Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GetMapping("/login")
- public String greetingForm(Model model) {
- model.addAttribute("User2", new User());
- return "login";
- }
- @PostMapping("/login")
- public String greetingSubmit(@ModelAttribute User regUser) {
- //userRepository.save(regUser);
- //String teststr = regUser.getName();
- //System.out.println(teststr);
- return "result";
- }
- <!DOCTYPE HTML>
- <html xmlns:th="http://www.thymeleaf.org">
- <head>
- <title>Getting Started: Handling Form Submission</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- </head>
- <body>
- <h1>Form</h1>
- <form action="#" th:action="@{/demo/login}" th:object="${User2}" method="post">
- <p>Username: <input type="text" th:field="*{name}" /></p>
- <p>Password: <input type="text" th:field="*{password}" /></p>
- <p>Balance: <input type="text" th:field="*{balance}" /></p>
- <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
- </form>
- </body>
- </html>
- @Entity // This tells Hibernate to make a table out of this class
- public class User {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private Integer id;
- private String name;
- private String password;
- private int balance;
- public int getBalance() {
- return balance;
- }
- public void setBalance(int balance) {
- this.balance = balance;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- <!DOCTYPE HTML>
- <html xmlns:th="http://www.thymeleaf.org">
- <head>
- <title>Getting Started: Handling Form Submission</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- </head>
- <body>
- <h1>Result</h1>
- <p th:text="'username: ' + ${User.name}" />
- <p th:text="'password: ' + ${regUser != null ? regUser.password : 'NOT FOUND'}" />
- <p th:text="'balance: ' + ${model != null ? regUser.balance : 'NOT FOUND'}" />
- <a href="/demo/login">Submit another user?</a>
- </body>
- </html>
- <p th:text="'username: ' + ${User.name}" />
- ${User2.name}
- ${User}
- ${User2}
- ${regUser.name}
- ${teststr}
- ${#User.name}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement