SpringMVC project to create a simple, entry

A, described in the context
to create a simple spring mvc
II environment
IntelliJ IDEA 2019
Tomcat 9.0.24
Process to
1. Create a new project
check the MVC the Spring, the Web the Application
Here Insert Picture Description
Here Insert Picture Description
2. Create a folder as shown in FIG
Here Insert Picture Description
3. import the relevant jar package to lib package created in the root directory can be directly copied over
Here Insert Picture Description
4 related configuration tomcat's
press F4 can project configuration
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
5. Add Web.xml profile on SpringMVC configuration
IDEA is very powerful, in fact, has given us with the the appropriate configuration, here we just need to make the appropriate changes according to their own projects. Here I will intercept the request type to intercept all requests
Here Insert Picture Description
6. Configure XXX-servlet.xml file
created in a jsp WEB / INF directory folder
spring mvc default start time will be loaded, at the end of the file XXX-servlet.xml .
Here Insert Picture Description

    <context:component-scan base-package="test.controller"/>

    <mvc:default-servlet-handler/>

    <mvc:annotation-driven/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

This is a screenshot increase code
7. Add hello.jsp file
Here Insert Picture Description
8. write the Controller
Here Insert Picture Description
9. Deployment Project
Here Insert Picture Description
! [Insert Picture description here] (https://img-blog.csdnimg.cn/20200306223618447.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR
Fill in the project name (recommended), this step can not write, you can fill in your favorite names on their own, but the proposal to write your own project name, application delivery routes context must be consistent and project name.
Fill in the project name (recommended), this step can not write, you can fill in your favorite names on their own, but the proposal to write your own projects name, publish the application context path and item name must be consistent.
10. Test
start tomcat server
, type http: // localhost: 8080 / project name / mvc / hello
Here Insert Picture Description

Released six original articles · won praise 16 · views 180

Guess you like

Origin blog.csdn.net/weixin_43894771/article/details/104706534