【Eclipse】springMVC介绍与配置

SpringMCV介绍:

Spring MVC是一种基于Java的实现了MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动的,也就是使用请求-响应模型,框架的目的就是帮助我们简化开发

MVC模式:

MVC 框架提供了模型-视图-控制的体系结构和可以用来开发灵活、松散耦合的 web 应用程序的组件。MVC 模式导致了应用程序的不同方面(输入逻辑、业务逻辑和 UI 逻辑)的分离,同时提供了在这些元素之间的松散耦合。

模型Model

    封装了应用程序数据,并且通常它们由 POJO 组成。

视图View

      主要用于呈现模型数据,并且通常它生成客户端的浏览器可以解释的 HTML 输出。

控制器Controller

主要用于处理用户请求,并且构建合适的模型并将其传递到视图呈现。

 

控制层的框架有哪些:

Struts 1.0 1.1

Spring mvc

Struts2  基于webwork

从性能上比较:

Jsp+servlet > struts1.1 > spring mvc > struts2

 创建demo

1 , 创建一个动态web工程。

2 , 加入Jar包。

 

3 ,  在web.xml中配置DispatcherServlet。

4 ,  加入Spring MVC的配置文件。

5 ,编写处下请求的处理器,并标识为处理器。

6, 编写视图。

创建配置文件:springmvc.xml 

 2、选择依赖:mvc、contxet、aop(看你需要)

  

结束:具体内容

<?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:aop="http://www.springframework.org/schema/aop"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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

<!-- 扫描包 -->
<context:component-scan base-package="com.jd.springmvc"></context:component-scan>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>      ---匹配在哪个地址下
<property name="suffix" value=".jsp"></property>            ---后缀
</bean>

</beans>

在web.xml中配置DispatcherServlet:前端控制器

<!--注册springmvc -->
<servlet>
  <servlet-name>bookstore</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:Spring-mvc.xml</param-value>---spring路劲
      </init-param>
      <load-on-startup>1</load-on-startup>----中1的取值1,2,3,4,5代表的是优先级正数的值越小,该servlet的优先级越高,应用启动时就越先加载
</servlet>
<servlet-mapping>
    <servlet-name>bookstore</servlet-name>
      <url-pattern>/</url-pattern>---过滤所有请求
</servlet-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知青先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值