Maven工程的SpringMVC结构的Web程序
来源:互联网 发布:monit windows agent 编辑:程序博客网 时间:2024/05/16 09:26
背景
之前一直在别人创建好的Web应用下写if-else,突然发现自己连创建一个SpringMVC结构的Web应用都要查半天。
所以,此篇特记录下,如何创建一个用Maven工程创建一个HelloWorld的web应用。
做法
创建一个Maven的Web项目
我用的IDE是IDEA,这里,先用IDEA创建一个Maven的Web项目。
添加修改配置文件
各个文件的内容:
1. pom.xml中引入依赖
2. web.xml中添加servlet(此时,spring-config-mvc.xml中还没有内容)
3. spring-config-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: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 http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 0.上面的那些头可以官网下载 --> <!-- 配置spring --> <!-- 1:开启SpringMVC注解模式 --> <!-- 简化配置: (1)自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter (2)提供一系列:数据绑定,数字和日期的format @NumberFormat,@DataTimeFormat,xml,json默认读写支持 --> <mvc:annotation-driven/> <!-- 2:servlet-mapping 映射路径:"/" --> <!-- 静态资源默认servlet配置 1.加入对静态资源的处理 2.欲需使用"/"做整体映射 --> <mvc:default-servlet-handler/> <!-- 3:配置jsp 显示ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 4:扫描web相关的bean --> <context:component-scan base-package="org.test.*" /></beans>
4.这个配置文件的第四步中,此时还没有对应的controller类
5.在org.test.controller包下新建HelloWorld类
package org.test.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/hello")public class HelloWorld { @RequestMapping("") public String hello(){ return "hello"; }}
6.第5步的HelloWorld类中,这个/hello
还没有对应的页面
7.新建hello.jsp页面
完成!
完整练习Demo:https://github.com/wayss000/PracticeCode/tree/master/helloweb
阅读全文
0 0
- Maven工程的SpringMVC结构的Web程序
- maven工程的结构
- 构建Maven+SpringMVC的Web工程(上)
- 构建Maven+SpringMVC的Web工程(下)
- IDEA 2017.1 基于Maven+SpringMVC的web工程
- Eclipse创建一个简单的Springmvc程序(Maven工程)
- SpringMVC的maven工程搭建
- 新建一个基于Maven的SpringMVC的Web工程遇到的问题
- 关于web工程的结构
- 使用maven 一步步构建springmvc的工程
- 建立基于maven 的springmvc mybatis工程
- 基于MAVEN的SSM(SPRING,SPRINGMVC,MYBATIS)整合的WEB工程
- eclipse搭建maven web 工程,和集成springmvc+mybatis的一些问题
- 搭建maven结构的web工程的时候,出现各种环境的问题的解决
- 一个Web应用部署到Tomcat服务器上之后的目录结构是怎样的?以及web工程与maven web工程的目录结构
- 使用maven和springMVC项目的结构
- 创建一个helloworld springmvc的web工程
- 配置文件分离的maven工程结构
- Educational Codeforces Round 32 B. Buggy Robot(模拟)
- nginx 从入门到实践 -基础篇(2)
- SpringMVC(2)-- 常用注解类
- 软件工程(C编码实践篇)学习总结
- Educational Codeforces Round 32 C. K-Dominant Character(模拟)
- Maven工程的SpringMVC结构的Web程序
- 17.11.9日报
- C语言03
- idea java web开发遇到的问题
- urllib模块使用笔记
- excel报内存或磁盘空间不足
- DateTime和TimeStamp
- Android-->Log系统,Logback的使用体验(slf4j)
- 习题6.7