SpringMVC工程搭建
2021-06-06 00:02
阅读:381
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
标签:body first 编写 cte rtu charset star ide springmvc
搭建配置SpringMVC
引入依赖
dependencies>
dependency>
groupId>junitgroupId>
artifactId>junitartifactId>
version>4.13.2version>
scope>testscope>
dependency>
dependency>
groupId>org.springframeworkgroupId>
artifactId>spring-webmvcartifactId>
version>5.2.13.RELEASEversion>
dependency>
dependency>
groupId>javax.servletgroupId>
artifactId>servlet-apiartifactId>
version>2.5version>
dependency>
dependency>
groupId>javax.servletgroupId>
artifactId>javax.servlet-apiartifactId>
version>4.0.1version>
scope>providedscope>
dependency>
dependencies>
配置静态资源导出
build>
resources>
resource>
directory>src/main/javadirectory>
includes>
include>**/*.propertiesinclude>
include>**/*.xmlinclude>
includes>
filtering>falsefiltering>
resource>
resource>
directory>src/main/resourcesdirectory>
includes>
include>**/*.propertiesinclude>
include>**/*.xmlinclude>
includes>
filtering>falsefiltering>
resource>
resources>
build>
Spring核心配置文件
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
">
beans>
编写Controller层
package controller;
@Controller
public class HelloController {
@RequestMapping("/hello")
public String hello(Model model){
model.addAttribute("msg","HELLO MY FIRST SPRING MVC PROJECT");
return "hello";
}
}
编写jsp
"text/html;charset=UTF-8" language="java" %>
Title
${msg}
编写web.xml
servlet>
servlet-name>springmvcservlet-name>
servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
servlet>
init-param>
param-name>contextConfigLocationparam-name>
param-value>classpath:applicationContext.xmlparam-value>
init-param>
load-on-startup>1load-on-startup>
servlet-mapping>
servlet-name>springmvcservlet-name>
url-pattern>/url-pattern>
servlet-mapping>
filter>
filter-name>encodingFilterfilter-name>
filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
init-param>
param-name>encodingparam-name>
param-value>utf-8param-value>
init-param>
filter>
filter-mapping>
filter-name>encodingFilterfilter-name>
url-pattern>/*url-pattern>
filter-mapping>
SpringMVC工程搭建
标签:body first 编写 cte rtu charset star ide springmvc
原文地址:https://www.cnblogs.com/IUaena/p/14618286.html
评论
亲,登录后才可以留言!