Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build SpringMVC Project

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report