Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.persistence.Entity;
- import javax.persistence.Id;
- @Entity
- public class User {
- @Id
- private int id;
- private String name;
- private int age;
- public User() {
- }
- public User(int id, String name, int age) {
- this.id = id;
- this.name = name;
- this.age = age;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- }
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import java.util.List;
- @Controller
- public class UserController {
- @Autowired
- private UserService userService;
- @RequestMapping(value = "/")
- public String display(ModelMap modelMap){
- User user = new User(1, "Endriyas", 21);
- userService.addUser(user);
- List<User> users = userService.getAllUser();
- modelMap.put("users", users);
- return "users";
- }
- }
- <div>
- <form action="#" th:action="@{/}" th:object="${users}" method="post">
- <div>
- <label>
- <span>ID</span>
- </label>
- <input type="number" th:field="*{id}"/>
- </div>
- <div>
- <label>
- <span>Name</span>
- </label>
- <input type="text" th:field="*{name}"/>
- </div>
- <div>
- <label>
- <span>Age</span>
- </label>
- <input type="number" th:field="*{age}"/>
- </div>
- <div>
- <button type="submit" name="save">SAVE</button>
- </div>
- </form>
- </div>
Add Comment
Please, Sign In to add comment