Spring MVC framework construction and configuration method and detailed explanation

Now the mainstream web MVC framework is spring MVC in addition to struts. Therefore, this is also the mainstream framework that a programmer needs to master. With more choices of frameworks, there are naturally more feasible schemes to deal with changing needs and businesses. However, if you want to flexibly use spring MVC to deal with most web development, you must master its configuration and principle.

1、 Construction of spring MVC environment: (spring 2.5.6 + hibernate 3.2.0)

1. Jar package import

  Spring 2.5. 6:spring. jar、spring-webmvc. jar、commons-logging. jar、cglib-nodep-2.1_ 3.jar

  Hibernate 3.6. 8:hibernate3. jar、hibernate-jpa-2.0-api-1.0. 1.Final. jar、antlr-2.7. 6.jar、commons-collections-3.1、dom4j-1.6. 1.jar、javassist-3.12. 0.GA. jar、jta-1.1. jar、slf4j-api-1.6. 1.jar、slf4j-nop-1.6. 4. Jar. Driver jar package of corresponding database

2. web. XML configuration (partial)

3. spring-servlet. XML configuration

Spring servlet is named because of the above web The value of < servlet name > tag in XML is spring (< servlet name > spring < / servlet name >), and the file name of spring-servlet.xml is formed by adding "- servlet" suffix. If it is changed to springmvc, the corresponding file name is springmvc-servlet.xml.

4. applicationContext. XML configuration

2、 Explain in detail

Spring MVC is similar to struts in principle (both are based on MVC Architecture). Both have a servlet that controls page requests and jump to the page after processing. See the following code (note):

The above four method examples are that a controller contains different request URLs, which can also be accessed by one URL. Different access methods can be distinguished by URL parameters. The code is as follows:

In fact, on the class, requestmapping can be regarded as the parent request URL, while on the method, requestmapping can be regarded as the child request URL. The parent-child request URL will eventually match the page request URL. Therefore, requestmapping can also be written as follows:

3、 Conclusion

Mastering the above spring MVC has a good foundation and can deal with almost any development. After mastering these, you can use more flexible technologies, such as a variety of view technologies, such as JSP, velocity, tiles, iText and poi. The spring MVC framework doesn't know which view to use, so it won't force you to use only JSP technology.

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
分享
二维码
< <上一篇
下一篇>>