1、新建项目

  参照idea教程中的创建maven项目https://www.cnblogs.com/daxiang2008/p/9061653.html

2、POM中加入依赖包

  (1)指定版本

  (2)配置依赖

3、配置web.xml

4、创建springMVC.xml

  配置 DispatcherServlet 的一个初始化参数: 配置 SpringMVC 配置文件的位置和名称,实际上也可以不通过 contextConfigLocation 来配置 SpringMVC 的配置文件, 而使用默认的.

其中servlet名是任意的,但是springmvc配置文件名是有要求的必须为,默认文件名为: <servlet-name>-servlet.xml

如:该文件名必须为: spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 不操作静态资源 -->
<mvc:default-servlet-handler/> <!-- 启用springmvc注解 (springmvc必须配置,用于@RequestMapping结合使用) -->
<mvc:annotation-driven/> <!-- 扫描所有的Controller 注:spring mvc容器只负责控制端处理 -->
<context:component-scan base-package="com.daxiang.kb.controler"/> <!-- 配置视图解析, InternalResourceViewResolver:视图名称解析器。 在这里prefix和suffix分别表示查找视图页面的前缀和后缀,
比如传进来的逻辑视图名为hello,那么该jsp视图页面应该存放在”/WEB-INF/jsp/hello.jsp” -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property><!-- 前缀 -->
<property name="suffix" value=".jsp"></property><!-- 后缀 -->
</bean> </beans>

 5、创建控制器

/**
* Copyright (C), 2018-2018,
* FileName: Query
* Author: 大象
* Date: 2018-09-17 14:32
*/
package com.daxiang.kb.controler; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; /**
* 〈〉<br>
*
* @author daxiang
* @create 2018-09-17
* @since 1.0.0
*/
@Controller
public class Query {
@RequestMapping("/hello")
public String hello(Model model) {
model.addAttribute("greeting", "Hello Spring MVC");
return "index"; }
}

  

最新文章

  1. Bubble Cup 8 finals I. Robots protection (575I)
  2. 内存提取SWF,破解doswf方法概述
  3. C#通过事件跨类调用WPF主窗口中的控件
  4. DOM何时Ready
  5. XMPP客户端开发(2)--发送接收消息
  6. 走着官方的教程入门Material Design(一)
  7. 《Java程序设计》第十周学习总结
  8. WPF处理Windows消息
  9. [Redux] Supplying the Initial State
  10. 关于DLL中Resources文件修改
  11. SQL Server MySQL 中的 in 与 null
  12. ASP.NET CS文件中输出JavaScript脚本
  13. java类中为什么设置set和get方法操作属性
  14. MySQL备份说明
  15. 小试ImageMagik——使用篇
  16. ASP.NET的版本?
  17. 第十五周翻译-《Pro SQL Server Internals, 2nd edition》
  18. [django]session设置与获取原理
  19. HTTP与TCP的区别和联系--转载
  20. java 基本数据类型及自动类型提升

热门文章

  1. Linux下安装confluence汉化破解版
  2. DBeaver下载安装与连接MySQL数据库
  3. python网络爬虫-入门(二)
  4. 【以太坊剖析】以太坊虚拟机(EVM)之基本定义
  5. 对线面试官,凭借nginx能一战封神吗?
  6. 密码学之PRP/PRF转换引理
  7. mac不能用ip访问项目的, 还有80端口不能开启的问题
  8. Android 实用开源库(不定期更新)
  9. 编译PHP扩展的方式
  10. SqlServer数据库表生成C# Model实体类SQL语句——补充