How to parse the example of automatic encapsulation of SpringMVC acceptance form
How to parse the SpringMVC accept form automatic encapsulation feature examples, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Controller in Spring MVC can accept form forms from clients as entity classes, and the fields of the form automatically form entity class objects.
Client-side form
Entity class
Public class User {private String name; private Integer age; private String hobby; public User () {this.name = "uninitialized"; this.age = 10; this.hobby = "coding";} public User (String name) {this.name = name; this.age = 10; this.hobby = "coding";} public User (String name, Integer age) {this.name = name; this.age = age; this.hobby = "coding";} public User (String name, Integer age, String hobby) {this.name = name This.age = age; this.hobby = hobby;} public Integer getAge () {return age;} public String getHobby () {return hobby;} public String getName () {return name;} public void setAge (Integer age) {this.age = age;} public void setHobby (String hobby) {this.hobby = hobby;} public void setName (String name) {this.name = name } @ Override public String toString () {return "User {" + "name='" + name +'\'+ ", age=" + age + ", hobby='" + hobby +'\'+'}';}}
Server receiving
@ Controller@RequestMapping ("/ test") public class TestController {@ RequestMapping (value = "/ user", method = RequestMethod.POST) / / the controller automatically instantiates the parameter public String user (User user) {System.out.println (user); return "redirect:/test/user";} @ RequestMapping (value = "/ user", method = RequestMethod.GET) public String user () {return "form";}}
After reading the above, do you know how to parse the SpringMVC accept form auto-encapsulation feature instance? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!