Guest User

Untitled

a guest
Mar 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import javax.persistence.Entity;
  2. import javax.persistence.Id;
  3.  
  4. @Entity
  5. public class User {
  6.  
  7. @Id
  8. private int id;
  9. private String name;
  10. private int age;
  11.  
  12. public User() {
  13. }
  14.  
  15. public User(int id, String name, int age) {
  16. this.id = id;
  17. this.name = name;
  18. this.age = age;
  19. }
  20.  
  21. public int getId() {
  22. return id;
  23. }
  24.  
  25. public void setId(int id) {
  26. this.id = id;
  27. }
  28.  
  29. public String getName() {
  30. return name;
  31. }
  32.  
  33. public void setName(String name) {
  34. this.name = name;
  35. }
  36.  
  37. public int getAge() {
  38. return age;
  39. }
  40.  
  41. public void setAge(int age) {
  42. this.age = age;
  43. }
  44. }
  45.  
  46. import org.springframework.beans.factory.annotation.Autowired;
  47. import org.springframework.stereotype.Controller;
  48. import org.springframework.ui.ModelMap;
  49. import org.springframework.web.bind.annotation.RequestMapping;
  50.  
  51. import java.util.List;
  52.  
  53. @Controller
  54. public class UserController {
  55.  
  56. @Autowired
  57. private UserService userService;
  58.  
  59. @RequestMapping(value = "/")
  60. public String display(ModelMap modelMap){
  61. User user = new User(1, "Endriyas", 21);
  62. userService.addUser(user);
  63. List<User> users = userService.getAllUser();
  64. modelMap.put("users", users);
  65. return "users";
  66. }
  67.  
  68. }
  69.  
  70. <div>
  71. <form action="#" th:action="@{/}" th:object="${users}" method="post">
  72. <div>
  73. <label>
  74. <span>ID</span>
  75. </label>
  76. <input type="number" th:field="*{id}"/>
  77. </div>
  78. <div>
  79. <label>
  80. <span>Name</span>
  81. </label>
  82. <input type="text" th:field="*{name}"/>
  83. </div>
  84. <div>
  85. <label>
  86. <span>Age</span>
  87. </label>
  88. <input type="number" th:field="*{age}"/>
  89. </div>
  90. <div>
  91. <button type="submit" name="save">SAVE</button>
  92. </div>
  93. </form>
  94. </div>
Add Comment
Please, Sign In to add comment