1.mcv框架要做哪些事情

(a)将url映射到java类或者Java类的方法

(b)封装用户提交的数据

(c)处理请求---调用相关的业务处理,封装响应的数据

(d)将封装的数据进行渲染,jsp,html等

2.SpringMvc是一个轻量级的基于请求响应的mvc框架

3.为什么要学习SpringMvc

性能比较好

简单、易学

与Spring无缝结合(使用Spring 的 IOC,AOP)

能够进行简单Junit测试

支持Restful风格

异常处理

本地化、国际化

数据验证、类型转换等

拦截器

等等

-------使用的人和公司多最主要

4.简单了解结构

5.做一个简单的SpringMvc 例子 (以下例子为 annotation例子)

(a)导入相关jar包

commons-logging-1.1.3.jar
spring-aop-4.2.2.RELEASE.jar (注解的时候需要)
spring-beans-4.2.2.RELEASE.jar
spring-context-4.2.2.RELEASE.jar
spring-context-support-4.2.2.RELEASE.jar
spring-core-4.2.2.RELEASE.jar
spring-expression-4.2.2.RELEASE.jar
spring-web-4.2.2.RELEASE.jar
spring-webmvc-4.2.2.RELEASE.jar

(b)配置分发器

  <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:mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

  

(c)添加SpringMvc配置文件 默认在web-inf下添加mvc.xml

(d)编写controller

package com.spring.hello;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
public class HelloController {
@RequestMapping("/hello")
public ModelAndView hello(HttpServletRequest req,HttpServletResponse resp)
{
ModelAndView mv=new ModelAndView();
mv.addObject("msg", "第一个annotation");
mv.setViewName("Hello");
return mv;
}
}

  

(e)编写SpringMvc文件即 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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<!-- 配置渲染器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!--配置结果视图的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!--配置结果视图的后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 配置请求和处理器 -->
<context:component-scan base-package="com.spring.hello"></context:component-scan>
</beans>

  

SpringMvc的简单介绍的更多相关文章

  1. SpringMVC的简单介绍及使用

    一.简介 1.SpringMVC和Spring的关系: >软件开发的三层架构: web层[表示层.表现层]---->Service层---->Dao[DataBase Access ...

  2. springmvc的简单介绍以及springmvc组件的介绍

    Spring web mvc框架 什么是springmvc Springmvc是spring框架的一个模块,spring和springmvc无需中间整合层整合 Springmvc是一个基于mvc的we ...

  3. springMVC原理简单介绍

    说明: 用户发送请求到DispatcherServlet,即前端控制器 DipatcherServlet调用处理器映射器HandlerMapping解析 处理器映射器HandlerMapping根据请 ...

  4. SpringMVC总结二:Controller的请求映射方式(RequestMapping)简单介绍

    在SpringMVC总结一:快速入门的基础上简单介绍一下请求映射的方式: 1,标准映射规则 1. @RequestMapping可以设置在类上,也可以设置在方法上 2. 请求的映射规则是:类上的Req ...

  5. Freemarker概念简单介绍

    Freemarker概念简单介绍 1.   Freemarker是什么 模板引擎:一种基于模板的,用来生成输出文本的通过工具. 基于java开发包和类库 2.   Freemarker能做什么 MVC ...

  6. JMS学习篇《一》ActiveMQ消息中间件的简单介绍与用法-概念篇

    原创说明:本篇博文为本人原创作品,转载请注明出处 1.何为消息中间件 消息中间件是一种在分布式应用中互相交换信息的一种技术,常见的成熟消息中间件有:RabbitMQ.SonicMQ,activeMQ. ...

  7. 简单介绍Struts2

    Struts2概述 Struts2虽然是Struts1的基础上发展起来的,但是实质上是以WebWork框架为核心,为传统的Struts1注入了WebWork的设计理念,统一了Struts1和WebWo ...

  8. SpringMVC之简单的增删改查示例(SSM整合)

    本篇文章主要介绍了SpringMVC之简单的增删改查示例(SSM整合),这个例子是基于SpringMVC+Spring+Mybatis实现的.有兴趣的可以了解一下. 虽然已经在做关于SpringMVC ...

  9. 转载 mvc:message-converters简单介绍 https://www.cnblogs.com/liaojie970/p/7736098.html

    mvc:message-converters简单介绍 说说@ResponseBody注解,很明显这个注解就是将方法的返回值作为reponse的body部分.我们进一步分析下这个过程涉及到的内容,首先就 ...

随机推荐

  1. centos6.5 mysql-server 5.1.73启动失败

    yum install mysql-server 安装mysql服务端会把相应的客户端也装上 service mysqld start  启动mysql服务 解决办法: 1.chomod 777  / ...

  2. AlloyTouch插件

    1.老样子引入js <script src="js/transform.js"></script> <script src="js/allo ...

  3. HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application 错误

    解决方法链接:http://stackoverflow.com/questions/17709076/http-status-500-the-absolute-uri-http-java-sun-co ...

  4. MySQL interval()函数

    INTERVAL(N,N1,N2,N3,..........) INTERVAL()函数进行比较列表(N,N1,N2,N3等等)中的N值.该函数如果N<N1返回0,如果N<N2返回1,如果 ...

  5. 在一个aspx或ashx页面里进行多次ajax调用

    在用ajax开发asp.net程序里.利用ashx页面与前台页面进行数据交互.但是每个ajax交互都需要一个ashx页面.结果是项目里一大堆ashx页面.使项目难以管理.现在我们就想办法让一个ashx ...

  6. .NetChajian

    Code generation(代码自动生成) NVelocity CodeSmith X-Code .NET XGoF - NMatrix / DEVerest Compilation(编译工具) ...

  7. ABAP 将单元格设置编辑状态 FORM

    FORM set_style  USING   fieldname                         style TYPE string                 CHANGING ...

  8. sed 命令

    使用sed操作: .个人博客的文件,只输出学生姓名 .txt .txt .只输出每个学生的url .txt .只输出个人博客里的学号 .txt .只输出个人博客中,两个字姓名的学生名 .txt .只输 ...

  9. .net WebApi开发

    1].部署环境.net4及以上版本. [2].vs2010  开发需单独安装vs2010 sp1和mvc4 mvc4:http://www.asp.net/mvc/mvc4 或者 http://dow ...

  10. 如何比较日期类型的String 大小浅谈.

    有三种解决方法: 第一种直接用字符串类的compareTo方法: String t1="20160707"; String t2="20160708"; int ...