Section 1 (configure the springmvc environment): learning the springmvc video tutorial from Silicon Valley, and learning the springmvc video from Silicon Valley.

Source: Internet
Author: User

Section 1 (configure the springmvc environment): learning the springmvc video tutorial from Silicon Valley, and learning the springmvc video from Silicon Valley.

I have been engaged in C # development. Later, after the company was changed, the leaders decided to use java for development, so they needed to collect relevant learning materials. This video tutorial is also suitable for you, so you can read and write it at the same time, so that you can remember it easily. If you encounter any difference, you can correct it.

Development Environment: win8 system, IntelliJ IDEA 2016.1.3.


1. The purpose of creating a maven project is to facilitate jar package update and maintenance. IntelliJ is very convenient and intelligent, and the project structure is automatically created to facilitate team development.
After creating a project, you need to import the springmvc-related development jar file. To manage the jar package file through maven, you only need to add the configuration in the pom. xml file.
The configuration is as follows:

<dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-aop</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-beans</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-context</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-tx</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-core</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-web</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-webmvc</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>jstl</groupId>  <artifactId>jstl</artifactId>  <version>1.2</version></dependency><dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-expression</artifactId>  <version>4.1.1.RELEASE</version></dependency><dependency>  <groupId>commons-logging</groupId>  <artifactId>commons-logging</artifactId>  <version>1.1.3</version></dependency><dependency>  <groupId>com.fasterxml</groupId>  <artifactId>classmate</artifactId>  <version>1.0.0</version></dependency><dependency>  <groupId>org.jboss.logging</groupId>  <artifactId>jboss-logging</artifactId>  <version>3.1.3.GA</version></dependency><dependency>  <groupId>javax.validation</groupId>  <artifactId>validation-api</artifactId>  <version>1.1.0.Final</version></dependency><dependency>  <groupId>org.jetbrains</groupId>  <artifactId>annotations-java5</artifactId>  <version>RELEASE</version></dependency><dependency>  <groupId>org.hibernate</groupId>  <artifactId>hibernate-validator</artifactId>  <version>5.1.3.Final</version></dependency><dependency>  <groupId>org.hibernate</groupId>  <artifactId>hibernate-validator-annotation-processor</artifactId>  <version>4.3.0.Final</version></dependency>
The compiler automatically downloads the relevant jar package files, even if the future update only changes the version number.
2. You need to find the web. xml file in webapp-> WEB-INF and create it manually if not.
Configure the interceptor servletDispatcher.
The configuration is as follows (related configuration parameters are described ):
<Servlet> <servlet-name> servletDispatcher </servlet-name> <servlet-class> org. springframework. web. servlet. DispatcherServlet </servlet-class> <! -- Configure the initialization parameters of DispatcherServlet: configure the position and name of the springmvc configuration file --> <init-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: springmvc. xml </param-value> </init-param> <! -- Start tomcat and load --> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-name> servletDispatcher </ servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> index. jsp </welcome-file> </welcome-file-list>
Note: classpath: springmvc. xml. This is the file for configuring springmvc in the future and needs to be created manually. Put it in the Code directory. If it is not referenced in the compiler, a red prompt will be prompted until the configuration is correct. 3. Configure the springmvc. xml file content
<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http://www.springframework.org/schema/context" xmlns: mvc = "http://www.springframework.org/schema/mvc" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/conte Xt http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd "> <! -- Configure the location of the spring scan package --> <context: component-scan base-package = "com. tellyes. springmvc"> </context: component-scan> <! -- Configure the view Parser: Resolve the return value of the handler Method to the actual physical path --> <bean class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/views/"> </property> <property name =" suffix "value = ". jsp "> </property> </bean> </beans> 4. Create a test class HelloWorld @ Controllerpublic class HelloWord {static String SUCCESS =" success "; /*** 1. Use the @ RequestiMapping annotation to map the request url. * 2. the return value is resolved to the actual physical view through the view parser. NalResourceViewResolver view parser, will be resolved as follows: */WEB-INF/views/success. jsp * @ return */@ RequestMapping ("/helloworld") private String helloworld () {System. out. print ("helloworld"); return SUCCESS ;}} as helloworld () returns the success name of the view, you need to create success under the views directory. jsp file content is random.
5. Compile and run the program on the port number and enter "/helloworld" to display the printed content on the console. The success. jsp page is displayed, indicating that the springmvc environment is successfully configured. It will be updated in the future, and the source code will be shared later because the code is relatively simple.
This video tutorial is a full set of tutorials from simple to deep.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.