最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringMVC的工程搭建步驟實現(xiàn)

 更新時間:2021年04月07日 14:25:49   作者:Ai清  
這篇文章主要介紹了SpringMVC的工程搭建步驟實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一、創(chuàng)建項目

1、新建一個項目名為:springmvc-demo-yuyongqing

右鍵項目名選擇Add Framework Support

在這里插入圖片描述

2、選擇Web Application

在這里插入圖片描述

3、配置SpringMVC

pom.xml

<dependencies>
<dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.13.2</version>
 <scope>test</scope>
</dependency>
<dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>5.2.13.RELEASE</version>
</dependency>
<dependency>
 <groupId>javax.servlet</groupId>
 <artifactId>servlet-api</artifactId>
 <version>2.5</version>
</dependency>
<dependency>
 <groupId>javax.servlet</groupId>
 <artifactId>javax.servlet-api</artifactId>
 <version>4.0.1</version>
 <scope>provided</scope>
</dependency>
</dependencies>

刷新maven后再加入如下圖所示代碼

在這里插入圖片描述

<build>
<resources>
 <resource>
  <directory>src/main/java</directory>
  <includes>
   <include>**/*.properties</include>
   <include>**/*.xml</include>
  </includes>
  <filtering>false</filtering>
 </resource>
 <resource>
  <directory>src/main/resources</directory>
  <includes>
   <include>**/*.properties</include>
   <include>**/*.xml</include>
  </includes>
  <filtering>false</filtering>
 </resource>
</resources>
</build>

二、配置核心文件

在這里插入圖片描述

1、

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context
  https://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/mvc
  https://www.springframework.org/schema/mvc/spring-mvc.xsd
 ">

<!-- bean definitions here -->

2、添加SpringMVC配置內(nèi)容

在這里插入圖片描述

 <!-- 自動掃描包,讓指定包下的注解生效,由IOC容器統(tǒng)一管理 -->
  <context:component-scan base-package="controller"/>
  
<!-- 1加載注解驅(qū)動 -->
<mvc:annotation-driven/>
 <!-- 2靜態(tài)資源過濾 -->
<mvc:default-servlet-handler/>
<!-- 3視圖解析器 -->
<bean id="internalResourceViewResolver" class=
 "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

3、Controller層

新建一個HelloController類

在這里插入圖片描述

 package controller;

@Controller
public class HelloController {

@RequestMapping("/hello")
public String hello(Model model){
 // Model 封裝數(shù)據(jù)
 model.addAttribute("msg","HELLO MY FIRST SPRING MVC PROJECT");

 // 返回的字符串就是視圖的名字 會被視圖解析器處理
 return "hello";
 }
}

4、JSP

在JSP包下新建hello.jsp

在這里插入圖片描述

 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <html>
 <head>
<title>Title</title>
 </head>
 <body>
${msg}
 </body>
 </html>

三、web.xml

1、配置前端控制器

<!-- 配置前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

2、配置初始化參數(shù)

<!-- 配置初始化參數(shù) -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationcontext.xml</param-value>
</init-param>

3、設(shè)置啟動級別

<!-- 設(shè)置啟動級別 -->
<load-on-startup>1</load-on-startup>
</servlet>

4、設(shè)置SpringMVC攔截請求

<!-- 設(shè)置SpringMVC攔截請求 -->
<servlet-mapping>
 <servlet-name>springmvc</servlet-name>
 <url-pattern> / </url-pattern> <!--攔截除.jsp的請求-->
</servlet-mapping>

5、亂碼過濾

 <!-- 亂碼過濾 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
 <param-name>encoding</param-name>
 <param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

6、運行web

打包
File→Project Structure

在這里插入圖片描述

刪除默認(rèn)的包

在這里插入圖片描述

在這里插入圖片描述

點ok→ok

在這里插入圖片描述

四、配置TomCat

1、點擊 Add Configuration… 進(jìn)入運行配置框

在這里插入圖片描述

2、點 + 選擇Tomcat Server 下的 Local

在這里插入圖片描述

3、點擊 Configure 選擇我們自己的TomCat

在這里插入圖片描述

在這里插入圖片描述

五、運行TomCat

在這里插入圖片描述

在瀏覽器輸入http://localhost:8080/hello

在這里插入圖片描述

在這里插入圖片描述

外鏈:
https://mvnrepository.com/

到此這篇關(guān)于SpringMVC的工程搭建步驟實現(xiàn)的文章就介紹到這了,更多相關(guān)SpringMVC的工程搭建 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • MyBatis?實現(xiàn)動態(tài)排序的多表查詢

    MyBatis?實現(xiàn)動態(tài)排序的多表查詢

    本文將展示如何在 Java 項目中結(jié)合 MyBatis 實現(xiàn)動態(tài)排序,尤其是在涉及多表查詢的情況下,具有一定的參考價值,感興趣的可以了解一下
    2024-05-05
  • IDEA中HTML通過servlet3.0注解名提交表單到servlet類找不到頁面的問題

    IDEA中HTML通過servlet3.0注解名提交表單到servlet類找不到頁面的問題

    這篇文章主要介紹了IDEA中HTML通過servlet3.0注解名提交表單到servlet類找不到頁面的問題,本文通過場景描述及問題解析,給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • 如何查看JVM使用的默認(rèn)的垃圾收集器

    如何查看JVM使用的默認(rèn)的垃圾收集器

    這篇文章主要介紹了如何查看JVM使用的默認(rèn)的垃圾收集器,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • spring 重復(fù)注解和aop攔截的實現(xiàn)示例

    spring 重復(fù)注解和aop攔截的實現(xiàn)示例

    本文主要介紹了spring 重復(fù)注解和aop攔截的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-08-08
  • java開發(fā)之基于Validator接口的SpringMVC數(shù)據(jù)校驗方式

    java開發(fā)之基于Validator接口的SpringMVC數(shù)據(jù)校驗方式

    這篇文章主要介紹了java開發(fā)之基于Validator接口的SpringMVC數(shù)據(jù)校驗方式,文中附含詳細(xì)示例代碼,有需要的朋友可以借鑒參考下
    2021-09-09
  • Java 動態(tài)生成類和實例, 并注入方法操作示例

    Java 動態(tài)生成類和實例, 并注入方法操作示例

    這篇文章主要介紹了Java 動態(tài)生成類和實例, 并注入方法操作,結(jié)合實例形式分析了Java 動態(tài)生成類和實例以及動態(tài)注入相關(guān)操作技巧,需要的朋友可以參考下
    2020-02-02
  • Java導(dǎo)出Excel通用工具類實例代碼

    Java導(dǎo)出Excel通用工具類實例代碼

    這篇文章主要給大家介紹了關(guān)于Java導(dǎo)出Excel通用工具類的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • SWT(JFace)體驗之StyledText類

    SWT(JFace)體驗之StyledText類

    有的時候Text需要實現(xiàn)這種那種的樣式。先提供在不使用StyledText類的情況:
    2009-06-06
  • Java壓縮文件操作詳解

    Java壓縮文件操作詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用Java語言進(jìn)行壓縮文件操作,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2022-08-08
  • maven中添加memcached.jar的配置步驟

    maven中添加memcached.jar的配置步驟

    在Java項目中使用Maven管理依賴時,如果需要添加??memcached.jar??依賴,可以通過本文介紹的步驟進(jìn)行配置,文章通過代碼示例講解的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-12-12

最新評論

霍城县| 南靖县| 永兴县| 北宁市| 江北区| 新巴尔虎右旗| 无锡市| 万载县| 长寿区| 乌鲁木齐市| 天峨县| 扎兰屯市| 丰城市| 沁水县| 玉溪市| 梁山县| 凌云县| 额济纳旗| 拉孜县| 新民市| 大英县| 凭祥市| 潞西市| 勐海县| 永济市| 克山县| 巫山县| 英超| 吉安县| 岳阳县| 锦屏县| 额敏县| 罗江县| 开平市| 永修县| 呼和浩特市| 安西县| 莆田市| 当涂县| 五峰| 屏边|