Detailed explanation of MVC module code in spring

The controller of spring MVC is used to process user requests. Controller is equivalent to action in struts 1. Their implementation mechanism and operation principle are similar

Controller is an interface, which generally directly inherits from abstracontroller and implements the handlerequestinternal method. The handlerequestinternal method is equivalent to the execute method of struts 1

Spring MVC has no built-in data encapsulation, and developers can encapsulate the data conversion code themselves

Spring MVC is unique in the processing of the view layer. Handlerequestinternal returns the modelandview object, which can be regarded as the encapsulation of JSP objects. Modelandiview accepts the path of the JSP page directly. For example, the parameter "cat / listcat" is only a part of the JSP path, and the actual complete path is "WEB-INF / JSP / cat / catlist JSP ", the parts before and after the path are configured in the configuration file

In addition to making JSP paths, modelandview can also directly pass model objects to the view layer without putting them into the request in advance, such as newmodelandview ("cat / listcat", "cat", cat). If multiple parameters are passed, map can be used, such as

Generally, a separate XML file is used, such as spring - action. XML XML specifically configures web related components

If a controller wants to process multiple business logic, you can use the multi actioncontroller, which is equivalent to the dispatchaction in struts 1. It can distribute different requests to different methods according to a certain parameter

Configure to spring action xml

summary

The above is all about the detailed explanation of MVC module code in spring. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>