java 版本 1.8.0_261

idea 版本2020.1

Tomcat 9
 maven 3.6
新建工程

File->new->project

默认会下载springframework5.2.3版本的框架文件下来。

工程的名称叫springtest

点击finish创建

编辑web.xml文件的内容

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--
url-pattern有5种配置模式: (1)/xxx:完全匹配/xxx的路径 (2)/xxx/*:匹配以/xxx开头的路径,请求中必须包含xxx。 (3)/*:匹配/下的所有路径,请求可以进入到action或controller,但是转发jsp时再次被拦截,不能访问jsp界面。 (4).xx:匹配以xx结尾的路径,所有请求必须以.xx结尾,但不会影响访问静态文件。 (5)/:默认模式,未被匹配的路径都将映射到刺servlet,对jpg,js,css等静态文件也将被拦截,不能访问。
-->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

  编辑dispatcher-serverlet.xml的内容

<?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-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd"
>
<!-- 配置controller的扫描包 -->
<context:component-scan base-package="test.controller"/> <!-- <mvc:default-servlet-handler/>-->
<!-- 配置注解驱动,相当于同时使用最新处理器映射器和处理器适配器,对json数据的响应提供支持-->
<mvc:annotation-driven/> <!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

  

在WEB_INF文件夹下新建jsp文件夹

在src下新建test、test.controller包

在test.controller包下新建

HelloWorldController.java
package test.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; @Controller
public class HelloWorldController {
//可以匹配/abc/hello.do但是不能匹配/hello.do
@RequestMapping("/*/hello.do")
public ModelAndView hello(){
return new ModelAndView("hello");
}
}

  

在WEB_INF/jsp/目录下新建hello.jsp

<%--
Created by IntelliJ IDEA.
User: 1688
Date: 2020-10-13
Time: 16:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link href="/springtest/static/css/demo.css" rel="stylesheet">
<head>
<title>Title</title>
</head>
<body>
<p class="text">hello</p>
</body>
</html>

  在根目录下新建

static/css/demo.css

.text{
color:#ff0000;
}

  项目的完整结构如下:

运行项目,编辑服务器:

如果一开始没有配置就点击左上角的+号,新建一个。配置跟上面一样。

按快捷键Ctrl+alt+Shift+S

选择Artifacts,右键右侧选项,点击Put into Output Root .点击OK

然后运行项目,打开浏览器访问:

http://localhost:8080/springtest/abc/hello.do

就可以看见预览的效果了。

idea如何新建一个springmvc 工程的更多相关文章

  1. Intellij IDEA新建一个EJB工程(二)

    从博文:http://www.cnblogs.com/yangyquin/p/5328344.html 中可以知道如何利用Intellij IDEA建立一个EJB Module,还有新建一个测试Mod ...

  2. 新建一个express工程,node app无反应

    1.问题描述 新建一个express工程,node app以后无反应,浏览器输入localhost:3000,显示如下 2.解决方法 在app.js文件中加入如下代码 app.listen(3000, ...

  3. Java Learning 001 新建一个Java工程 HelloWorld程序

    Java Learning 001 新建一个Java工程 HelloWorld程序 Step 1 . 在Eclipse 软件里,点击: File -> New -> Java Projec ...

  4. Proteus 8使用 1新建一个Proteus工程

    新建一个Proteus工程 下一步 创建部分结束,可以看到两部分-->原理图与源代码. 首先按下F7或从“构建”菜单中选择“构建工程” 之后切换到原理图窗口 按下F12或点击窗口最左下角的“运行 ...

  5. zynq学习01 新建一个Helloworld工程

    1,好早买了块FPGA板,zynq 7010 .终极目标是完成相机图像采集及处理.一个Window C++程序猿才开始学FPGA,一个小菜鸟,准备转行. 2,关于这块板,卖家的官方资料学起来没劲.推荐 ...

  6. Android中使用自身携带的Junit新建一个测试工程

    1.新建立一个Android工程 package com.shellway.junit; public class Service { public int divide(int a,int b){ ...

  7. Android问题-打开DelphiXE8与DelphiXE10新建一个空工程提示"out of memory"

    错误信息: [DCC Error] E2597 d:\XE8\Embarcadero\Studio\16.0\PlatformSDKs\android-ndk-r9c\toolchains\arm-l ...

  8. 【Struts2】新建一个Struts2工程,初步体验MVC

    实现目标 地址栏输入http://localhost:88/Struts2HelloWorld/helloworld.jsp 输入用户名,交由http://localhost:88/Struts2He ...

  9. (一)SpringMvc简介以及第一个springmvc工程

    一.SpringMVC是什么? springmvc是Spring的一个模块,提供web层解决方案(就与MVC设计架构) 如上图, DispatcherServlet:前端控制器,由SpringMVC提 ...

随机推荐

  1. uni-app 修改富文本信息中的图片样式

    var richtext= res.data.data.richtext; const regex = new RegExp('<img', 'gi'); richtext= richtext. ...

  2. codewars sum of pairs

    Sum of Pairs Given a list of integers and a single sum value, return the first two values (parse fro ...

  3. 小白也能弄懂的目标检测之YOLO系列 - 第一期

    大家好,上期分享了电脑端几个免费无广告且实用的录屏软件,这期想给大家来讲解YOLO这个算法,从零基础学起,并最终学会YOLOV3的Pytorch实现,并学会自己制作数据集进行模型训练,然后用自己训练好 ...

  4. vue中实现后台管理路由标签页

    <template> <section> <div class="navTabList el-tabs__nav-scroll" id="t ...

  5. oracle中创建用户,指定要查询的视图 --九五小庞

    --01: 创建PACS用户,并且初始密码为PACScreate user PACS identified by "PACS"; --02: 赋予该用户登录数据库的权限.grant ...

  6. pytest文档2-pytest+Allure+jenkins+邮箱发送

    前言: 上一章节讲解了tomcat+jenkins的环境搭建,这一章节主要讲一下Allure报告在jenkins上的配置 步骤: 1.新建一个item 2.输入项目的名称,选择自由风格,点击保存 3. ...

  7. [LeetCode]1249. 移除无效的括号(字符串,栈)

    题目 给你一个由 '('.')' 和小写字母组成的字符串 s. 你需要从字符串中删除最少数目的 '(' 或者 ')' (可以删除任意位置的括号),使得剩下的「括号字符串」有效. 请返回任意一个合法字符 ...

  8. 使用阿里云OSS的服务端签名后直传功能

    网站一般都会有上传功能,而对象存储服务oss是一个很好的选择.可以快速的搭建起自己的上传文件功能. 该文章以使用阿里云的OSS功能为例,记录如何在客户端使用阿里云的对象存储服务. 服务端签名后直传 背 ...

  9. js监听事件的绑定与移除

    监听事件的绑定与移除主要是addEventListener和removeEventListener的运用. addEventListener语法 element.addEventListener(ty ...

  10. hystrix源码之hystrix请求变量

    HystrixRequestContext 请求的上线文实现,内部定义了一个静态变量ThreadLocal,每个线程可以获取自己的HystrixRequestContext对象.一个请求往往由一个to ...