Get the App
SLTechnology News&Howtos  ›  Development  › 

How to build SpringMVC Project

Shulou Source: shulou.com Published: 2022-06-01 12:28:34 09月13日 Update

This article mainly explains "how to build the SpringMVC project". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build the SpringMVC project.

First, create a project

1. Create a new project called springmvc-demo-yuyongqing

Right-click the project name and select Add Framework Support

2. Select Web Application

3. Configure SpringMVC

Pom.xml

Junit junit 4.13.2 test org.springframework spring-webmvc 5.2.13.RELEASE javax.servlet servlet-api 2.5 javax.servlet javax.servlet-api 4.0.1 provided

Refresh the maven and then add the following code

Src/main/java * * / * .properties * * / * .xml false src/main/resources * * / * .properties * * / * .xml false II, configuration core file

1 、

2. Add SpringMVC configuration content

3. Controller layer

Create a new HelloController class

Package controller;@Controllerpublic class HelloController {@ RequestMapping ("/ hello") public String hello (Model model) {/ / Model encapsulates data model.addAttribute ("msg", "HELLO MY FIRST SPRING MVC PROJECT"); / / the returned string is the name of the view that will be processed by the view parser return "hello";}}

4 、 JSP

Create a new hello.jsp under JSP package

Title ${msg} III, web.xml

1. Configure the front controller

Springmvcorg.springframework.web.servlet.DispatcherServlet

2. Configure initialization parameters

ContextConfigLocationclasspath:applicationcontext.xml

3. Set the startup level

one

4. Set SpringMVC to intercept requests

Springmvc /

5. Garbled code filtering

EncodingFilterorg.springframework.web.filter.CharacterEncodingFilter encoding utf-8encodingFilter/*

6. Run web

Packing

File → Project Structure

Delete the default package

Point ok → ok

4. Configure TomCat

1. Click Add Configuration … Enter the running configuration box

2. Click + Select Local under Tomcat Server

3. Click Configure to select our own TomCat

5. Run TomCat

Enter http://localhost:8080/hello in the browser

At this point, I believe you have a deeper understanding of "how to build the SpringMVC project". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Configuration selection engineering content project run view learning utility deeper garbled code interest front end package point parameter name character string practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS vpn Shulou Information Redmi