一、项目配置

还记得刚开始学习ssm框架时,感觉配置特别的麻烦,总是配置不对。于是三分钟热度的我放弃了很多次,现在了解了,给大家贴出来最简单的SpringMVC配置。不过还是建议大家学习SpringBoot,因为SpringBoot配置简单并且又是新推出的框架,未来发展的趋势。废话不多说,上代码!

1、项目结构

2、web.xml

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"><display-name>upms-server</display-name><!-- Spring的配置--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:spring-servlet.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- springMVC的核心控制器 --><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath*:springMVC-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springMVC</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>

3、父pom.xml

<properties><spring.version>4.3.20.RELEASE</spring.version></properties><!-- 依赖声明 --><dependencyManagement><dependencies> <dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency></dependencies></dependencyManagement>

4、pom.xml

     <dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId></dependency></dependencies>

5、spring-servlet.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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd  "></beans>

6、springMVC-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd "><!-- 下面是配置扫描包的位置,包名为com.ework.upms.server,也就是说,我们的试图解析器应该放在com.ework.upms.server包下. --><context:component-scan base-package="com.ework.upms.server"/><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 前缀,我们的视图文件应该放到/WEB-INF/views/目录下,这里我们需要在WEB-INF下面创建view文件夹 --><property name="prefix" value="/WEB-INF/views/" /><!-- 设置后缀为.jsp --><property name="suffix" value=".jsp" /></bean></beans>

二、Controller控制器及jsp页面

1、index.jsp

<html>
<body><h2>Hello World!</h2><a href="${pageContext.request.contextPath}/hello">hello</a>
</body>
</html>

2、hello.jsp

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

3、控制器-IndexController

@Controller
public class IndexController {@RequestMapping("/hello")public ModelAndView hello() {ModelAndView modelAndView=new ModelAndView();modelAndView.addObject("name","zhangsan");modelAndView.setViewName("hello");return modelAndView;}
}

三、运行效果图

1、index页面

2、hello页面

转载于:https://www.cnblogs.com/yansg/p/11312265.html

最简单的SpringMVC + Maven配置相关推荐

  1. Maven+SpringMVC+Dubbo+zookeeper 简单的入门demo配置

    参考:http://blog.csdn.net/aixiaoyang168/article/details/51362675 dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调 ...

  2. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  3. 基于注解配置简单的SpringMVC+Mybatis

    SpringMVC+Mybatis框架配置过好几次了,现在貌似终于对这些东西有些了解,自己草草的总结一下,也是再学习的一个过程. 首先,准备jar包,这个就不在赘述了. 然后就来肉戏了,以下只是我的理 ...

  4. mac maven 配置。简单四步

    一.maven 下载选择下载版本吧 多版本maven下载链接 我这里选择下载3.6.3 二.解压下载的包 我这里是新建了一个专门放maven 的文件夹,根据项目需要选择不同的版本 三.配置maven环 ...

  5. slf4j 和 log4j的关系及合用Maven配置

    最近因为项目实在是太忙,都没有时间学习.有时候会很矛盾,一方面是全心全意的想去快速做完项目,一方面又想学习点新东西.这样导致这两三个月都没有去学习一些新的东西,这周我开始创建自己的maven项目,因为 ...

  6. 框架写mysql插入为空_学习springMVC框架配置遇到的问题-数据写入不进数据库时的处理办法...

    Idea简单SpringMVC框架配置 前边已经介绍过了Struts在Idea上的配置,相对于Struts来说,我觉得SpringMVC有更多的优势,首先Struts是需要对action进行配置,页面 ...

  7. SpringMvc框架配置过滤器

    SpringMvc框架配置过滤器 本文以简单的登录过滤器为例 开发环境 jdk 8 idea2019.3.5 maven 3.6.3 spring-webmvc 5.1.9.RELEASE web.x ...

  8. 使用注解开发SpringMVC详细配置教程

    目录 1.使用注解开发SpringMVC 1.新建一个普通的maven项目,添加web支持 2.在pom.xml中导入相关依赖 3.配置web.xml 4.编写SpringMVC配置文件 1. 自动扫 ...

  9. SpringInAction--Spring Web应用之SpringMvc 注解配置

    Spring MVC 是当前Web服务器中常用的结构,今天就来学习这相关的知识,首先上图--Spring请求的时候所经历的坎坷之路: (书上原话,算是解释..) 在请求离开浏览器时① ,会带有用户所请 ...

最新文章

  1. Himmelblau函数优化实战
  2. SharePoint 2013 配置基于AD的Form认证
  3. gtk移植到嵌入式_物联网时代的盛行,应届毕业生是学嵌入式好呢,还是安卓或ios呢?...
  4. vb.net2019- 机器学习ml.net情绪分析(1)
  5. IdentityServer4实战 - 基于角色的权限控制及Claim详解
  6. linux:tr的用法
  7. Swing编程基础 之三
  8. AQS及其组件的核心原理
  9. iPhone 或将告别 3D Touch ?
  10. TensorFlow.js 来了!浏览器上线机器学习功能
  11. python列表append()函数
  12. win7升级旗舰版密钥_WIN7无人值守应答文件的制作
  13. python plc fx5u_三菱PLC FX5U系列模块型号对照一览表
  14. 宏基笔记本电脑怎么进入bios设置功能按键图解
  15. 计算机二级表格题的数据,计算机二级Excel表格题库答案(解题步骤)
  16. 驾考一点通维语版_驾考宝典维语版
  17. EVE 设备开机时的更改连线
  18. npm全局安装和本地安装及卸载
  19. VUE饿了么学习笔记(6)goods界面滚动和点击联动的实现
  20. git报错ssh: Could not resolve hostname dev-nys: Name or service not known fatal: Could not read from r

热门文章

  1. 理解卡夫卡的初学者指南
  2. Python 2 结束支持,Ubuntu 20.04 LTS 继续进行将其移除的工作
  3. DiQuick Web UI 框架 V1.3 正式版发布
  4. Odoo10教程---模块化二:模型间关系,继承,计算字段等
  5. python 函数可以作为容器对象的元素_14、函数对象和闭包
  6. micropython c语言_micropython mp对象和c类型的转换
  7. 计算营业额python_ARIMA时间序列分析-----Python实例(一周销售营业额预测)
  8. 计算机安全的加密技术,计算机安全加密技术研究(4篇)(共14695字).doc
  9. 64位指针膨胀 java_64位JVM带来的问题及解决方案
  10. 在iView中动态创建表格