• 【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.xsd
    http://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>

    学着把生活的苦酒当成饮料一样慢慢品尝, 不论生命经过多少委屈和艰辛, 我们总是以一个朝气蓬勃的面孔, 醒来在每一个早上。
  • 相关阅读:
    Tomcatd断点调试Debug
    idea怎么部署Servlet
    ECMAScript基本语法——①与HTML的结合方式
    JavaScript简介
    程序员找工作,应该怎么应对面试官?
    你所未知的3种 Node.js 代码优化方式
    对 APM 用户的一次真实调查分析(上)
    Datadog Agent是啥?它消耗什么资源?
    Python 全栈开发 -- 开发环境篇
    成为运维界的「福尔摩斯」,你还需要3个帮手!
  • 原文地址:https://www.cnblogs.com/yhm9/p/10502857.html
Copyright © 2020-2023  润新知