springMVC基础框架搭建
1.导入springMVC相关jar包:

2.添加Web.xml配置文件中关于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>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3.在src下添加springmvc-servlet.xml配置文件
<!-- scan the package and the sub package -->
<context:component-scan base-package="test.SpringMVC"/>
<!-- don't handle the static resource -->
<mvc:default-servlet-handler />
<!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven />
<!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 配置后台返回跳转到jsp页面 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
4.在WEB-INF文件夹下创建名为jsp的文件夹,用来存放jsp视图。创建一个hello.jsp
5.建立包及Controller,如下所示:

6.编写Controller代码:
@Controller
@RequestMapping("/mvc")
public class mvcController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
@ResponseBody
@RequestMapping("/hello2")
public String hello2(){
System.out.println("hello2");
return "hello2";
}
}
代码说明:如果执行方法后需要返回到jsp页面,方法上面就不要加@ResponseBody;
如果执行方法体返回方法的结果则需要加:@ResponseBody注解
7.启动服务器,键入 http://localhost:8080/项目名/mvc/hello
更多参考:http://www.admin10000.com/document/6436.html
springMVC基础框架搭建的更多相关文章
- springboot+mybatis+springMVC基础框架搭建
项目结构概览 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http: ...
- SSM(Spring +SpringMVC + Mybatis)框架搭建
SSM(Spring +SpringMVC + Mybatis)框架的搭建 最近通过学习别人博客发表的SSM搭建Demo,尝试去搭建一个简单的SSMDemo---实现的功能是对用户增删改查的操作 参考 ...
- LayIM.AspNetCore Middleware 开发日记(三)基础框架搭建
前言 在上一篇中简单讲了一些基础知识,例如Asp.Net Core Middleware 的使用,DI的简单使用以及嵌入式资源的使用方法等.本篇就是结合基础知识来构建一个基础框架出来. 那么框架有什么 ...
- SpringMVC+Mybatis框架搭建
一.新建javaweb项目,并建好相应的包结构 二.添加项目jar到lib目录下 三.在config包中新建配置文件 sping-mvc.xml,内容如下: <?xml version=&quo ...
- 新手SSH基础框架搭建
SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架. 首先我们先了解SSH的框架所需的包和基本概念: 一.下面我们先来了解一下strut ...
- 【SSM 6】Spring+SpringMVC+Mybatis框架搭建步骤
一.整体概览 首先看maven工程的创建 二.各层的文件配置 2.1,SSM父工程 <span style="font-family:KaiTi_GB2312;font-size:18 ...
- spring+springmvc+mybatis框架搭建
一.开发前准备 1)ecplise4.11.0 百度网盘:https://pan.baidu.com/s/1wO9_I52lp0mYNeNTdnj80w 提取码:booa 2)jdk1.6.0_45 ...
- 基于Maven的ssm(spring+springMvc+Mybatis)框架搭建
前言 本demo是在idea下搭建的maven项目,数据库使用Mysql,jdk版本是1.8.0_171,ideal:2017.3.5 一.新建项目 1.file->new->porjec ...
- SpringMvc+Mybatis 框架搭建
本文承接上一篇[idea使用maven搭建springmvc] 开篇:在main/resources下新建dbconfig.properties.spring.xml.spring-mybatis.x ...
随机推荐
- [MyBatis]最简MyBatis工程
下载地址:https://files.cnblogs.com/files/xiandedanteng/fillMillionDatum01_191005.rar --END-- 2019年10月5日1 ...
- LC 781. Rabbits in Forest
In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how ...
- ObjectId初探
ObjectId MongoDB每个集合存储的每个文档必须有一个"_id"键,默认是个ObjectId对象. "_id"作为当前文档在集合的唯一标识. 71st ...
- Qt编写自定义控件15-百分比仪表盘
前言 百分比仪表盘,主要的应用场景是展示销售完成率.产品合格率等,也可以作为一个进度百分比展示,可以独立设置对应的标题文字,标题文字的颜色和整体的颜色都可以单独设置,建议设置成统一的风格,这样会显得更 ...
- python同时执行两个函数
使用两个线程同时执行两个函数, def fun1(): while True: time.sleep(2) print("fun1") def fun2(): while True ...
- 【Rxjs】 - 解析四种主题Subject
原文地址: https://segmentfault.com/a/1190000012669794 引言 开发ngx(angular 2+)应用时,基本上到处都会用到rxjs来处理异步请求,事件调用等 ...
- WebApi实现通讯加密 (转)
http://www.cnblogs.com/jonneydong/p/WebApi_Encryption.html 一. 场景介绍: 如题如何有效的,最少量的现有代码侵入从而实现客户端与服务器之间的 ...
- Redis安装与配置( Windows10 )
本文链接:https://blog.csdn.net/gaokcl/article/details/82814134linux安装参考:https://blog.csdn.net/gaokcl/art ...
- PhpSpreadSheet 读写excel文件
phpoffice 系列很好用.PhpSpreadSheet取代了原先的phpexcel,用来处理excel文件 https://phpspreadsheet.readthedocs.io/en/la ...
- 修改注册表打开PDF内嵌的zip等文件
今天在打开一个 PDF 文件的时候,发现文件里面嵌入的 .zip 文件无法打开.当然 .png 之类的文件还是可以打开的.网上的各种“信任管理器”白名单方法都是无效的.后来查了官网说明,得知是因为这类 ...