Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse the example of automatic encapsulation of SpringMVC acceptance form

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report