当前位置: 首页 > news >正文

做的很酷炫的网站腾讯企点app

做的很酷炫的网站,腾讯企点app,移动端模板网站建设价格,查看域名之前做的网站目录 引言1. 什么是SpringMVC?1.1. 模型1.2. 视图1.3. 控制器 2. SpringMVC的工作流程2.1. 客户端发送请求2.2. DispatcherServlet的处理2.3. 处理器映射器的使用2.4. 处理器的执行2.5. 视图解析器的使用2.6. 视图的渲染 3. SpringMVC的核心组件4. 弹簧MVC总结 引言 SpringMV…

目录

  • 引言
    • 1. 什么是SpringMVC?
      • 1.1. 模型
      • 1.2. 视图
      • 1.3. 控制器
    • 2. SpringMVC的工作流程
      • 2.1. 客户端发送请求
      • 2.2. DispatcherServlet的处理
      • 2.3. 处理器映射器的使用
      • 2.4. 处理器的执行
      • 2.5. 视图解析器的使用
      • 2.6. 视图的渲染
    • 3. SpringMVC的核心组件
    • 4. 弹簧MVC
    • 总结

在这里插入图片描述

引言

SpringMVC是一个流行的Java Web开发框架,它提供了一种优雅的方式来构建灵活、可扩展的Web应用程序。本文将介绍SpringMVC的基本概念,深入探讨其工作流程和核心组件,并提供一个入门程序来帮助读者快速上手。

1. 什么是SpringMVC?

SpringMVC是基于Java的MVC(Model-View-Controller)设计模式的Web框架。它通过将应用程序分为模型、视图和控制器三个部分,实现了松耦合和高内聚的架构。SpringMVC提供了丰富的功能和灵活的配置选项,使得开发者能够快速构建可维护和可扩展的Web应用程序。

1.1. 模型

模型代表应用程序的数据和业务逻辑。它可以是一个POJO(Plain Old Java Object)或一个持久化实体类。模型负责处理数据的读取、存储和验证,并提供给视图和控制器使用。

1.2. 视图

视图负责展示模型的数据给用户。它可以是一个JSP页面、HTML模板或其他类型的视图技术。视图通常是被动的,只负责展示数据,不处理业务逻辑。

1.3. 控制器

控制器接收用户的请求并根据请求的内容选择合适的处理逻辑。它负责处理用户输入、调用模型的方法来处理数据,并将处理结果传递给视图进行展示。

2. SpringMVC的工作流程

SpringMVC的工作流程可以分为以下几个步骤:

2.1. 客户端发送请求

  1. 用户发来一个请求,首先进入的是前端控制器DispatcherServlet

2.2. DispatcherServlet的处理

  1. 前端控制器(DispacherServlet)将用户发来的请求发送给处理器映射器(HandlerMapping)
  2. 处理器映射器根据前端控制器发来的用户的请求找到对应符合的控制器(Handler),并且将其封装成处理器执行链,返回给前端控制器。

2.3. 处理器映射器的使用

  1. 处理器适配器 (HandlerAdaptoer) 会调用对应的具体的 Controller(处理业务逻辑)
  2. 处理器适配器接收到来自前端控制器的执行链后,找到对应执行此执行链的处理器适配器(HandlerAdapter)来调用的具体的控制器(就是说其对应的方法或者逻辑)

2.4. 处理器的执行

  1. 控制器执行完成后,会返回一个ModelAndView对象给处理器适配器
  2. 处理器适配器将返回来的ModelAndView对象返回给前端控制器(到这里所有的业务处理过程就要完了,接下就是将结果以页面的的形式响应给用户)

2.5. 视图解析器的使用

  1. 前端控制器将返回回来的ModelAndView对象交给视图解析器(ViewResolver),视图解析器根据传过来的View对象解析成对应的页面对象
  2. ViewResolver 将封装好的将页面对象和Model对象返回给 DIspatcherServlet

2.6. 视图的渲染

  1. 前端控制器再将返回回来的对象交给视图(View)
  2. 视图根据传过来的Model对象再一次的对页面进行渲染(将模型数据填充至视图中),然后在返回给前端控制器。
  3. 前端控制器将完成的结果响应给浏览器,然后浏览器在展现给用户。

3. SpringMVC的核心组件

SpringMVC的核心组件包括:

  • 3.1. 调度程序服务版
    DispatcherServlet是SpringMVC的前端控制器,负责接收和分发请求。
  • 3.2. 处理器映射器(处理程序映射)
    处理器映射器负责将请求映射到合适的处理器(Controller)。
  • 3.3. 处理器适配器(处理程序适配器)
    处理器适配器负责调用处理器的方法来处理请求。
  • 3.4. 视图解析器(View Resolver)
    视图解析器负责将逻辑视图名解析为真正的视图对象。
  • 3.5. 视图(视图)
    视图负责展示处理结果给用户。

4. 弹簧MVC

下面是一个简单的SpringMVC入门程序的示例:
4.1. 创建Maven项目
首先,我们需要创建一个Maven项目,并添加SpringMVC的依赖。
pom.xml依赖

<!-- jstl+standard -->
<jstl.version>1.2</jstl.version>
<standard.version>1.1.2</standard.version>
<!-- spring -->
<spring.version>5.0.2.RELEASE</spring.version>
...
<!-- spring mvc相关依赖 -->
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version>
</dependency>
<dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>${jstl.version}</version>
</dependency>
<dependency><groupId>taglibs</groupId><artifactId>standard</artifactId><version>${standard.version}</version>
</dependency>

4.2. 配置网页.xml
在web.xml文件中,我们需要配置DispatcherServlet和Spring容器。
4.3. 创建控制器
创建一个spring-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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--1) 扫描com.zking.zf及子子孙孙包下的控制器(扫描范围过大,耗时)--><context:component-scan base-package="com.yuan"/><!--2) 此标签默认注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter --><mvc:annotation-driven /><!--3) 创建ViewResolver视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- viewClass需要在pom中引入两个包:standard.jar and jstl.jar --><property name="viewClass"value="org.springframework.web.servlet.view.JstlView"></property><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><!--4) 单独处理图片、样式、js等资源 --><!-- <mvc:resources location="/css/" mapping="/css/**"/><mvc:resources location="/js/" mapping="/js/**"/><mvc:resources location="WEB-INF/images/" mapping="/images/**"/>-->
</beans>

demo1Controller.java

package com.yuan.web;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;/*** @author 叶秋* @site* @company 卓京公司* @create 2023-09-04 17:01*/
@Controller
@RequestMapping("/main")
public class demo1Controller {@RequestMapping("/index")public String demo1(){System.out.println("hello  spring");return "index";}
}

4.4. 配置SpringMVC
在Spring的配置文件中,我们需要配置处理器映射器、视图解析器等。
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"><display-name>Archetype Created Web Application</display-name><!-- Spring和web项目集成start --><!-- spring上下文配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-context.xml</param-value></context-param><!-- 读取Spring上下文的监听器 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Spring和web项目集成end --><!-- 中文乱码处理 --><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><async-supported>true</async-supported><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- Spring MVC servlet --><servlet><servlet-name>SpringMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--此参数可以不配置,默认值为:/WEB-INF/springmvc-servlet.xml--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup><!--web.xml 3.0的新特性,是否支持异步--><async-supported>true</async-supported></servlet><servlet-mapping><servlet-name>SpringMVC</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

4.5. 编写JSP视图
创建一个JSP视图来展示处理结果。

<%--Created by IntelliJ IDEA.User: yuanhDate: 2023/9/4Time: 17:04To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Title</title>
</head>
<body>
hello word</body>
</html>

4.6. 运行程序
最后,我们可以运行程序并在浏览器中访问相应的URL来查看结果。
在这里插入图片描述

总结

本文深入探讨了SpringMVC的工作原理和核心组件,并提供了一个入门程序来帮助读者快速上手。通过理解SpringMVC的工作流程和组件的作用,开发者可以更好地使用该框架来构建高效、可靠的Web应用程序。希望本文对您有所帮助,谢谢阅读!

补充:访问资源绕过解析器不被拦截代码

 <!--4) 单独处理图片、样式、js等资源 --><!-- <mvc:resources location="/css/" mapping="/css/**"/><mvc:resources location="/js/" mapping="/js/**"/><mvc:resources location="WEB-INF/images/" mapping="/images/**"/>--><mvc:resources location="/static/" mapping="/static/**"/>

文章转载自:
http://dinncocongregational.tqpr.cn
http://dinncochiliasm.tqpr.cn
http://dinncophotoglyphy.tqpr.cn
http://dinncoexility.tqpr.cn
http://dinncomayest.tqpr.cn
http://dinncomastercard.tqpr.cn
http://dinncobolograph.tqpr.cn
http://dinncocanty.tqpr.cn
http://dinncoopportune.tqpr.cn
http://dinncotug.tqpr.cn
http://dinncodigitalis.tqpr.cn
http://dinncohysteresis.tqpr.cn
http://dinncogowk.tqpr.cn
http://dinncospringiness.tqpr.cn
http://dinncoyell.tqpr.cn
http://dinncofenman.tqpr.cn
http://dinncoeugenia.tqpr.cn
http://dinncoahwaz.tqpr.cn
http://dinncoleary.tqpr.cn
http://dinnconajaf.tqpr.cn
http://dinncoparotid.tqpr.cn
http://dinncomonistical.tqpr.cn
http://dinncobeard.tqpr.cn
http://dinncofictional.tqpr.cn
http://dinncoexcurrent.tqpr.cn
http://dinncocomfrey.tqpr.cn
http://dinncosubotica.tqpr.cn
http://dinncoeluviate.tqpr.cn
http://dinncoamphibiotic.tqpr.cn
http://dinncoecuador.tqpr.cn
http://dinncopetala.tqpr.cn
http://dinncoclasser.tqpr.cn
http://dinncotarsia.tqpr.cn
http://dinncoshrug.tqpr.cn
http://dinncothermojet.tqpr.cn
http://dinncoelectrolier.tqpr.cn
http://dinncoregret.tqpr.cn
http://dinncomirthless.tqpr.cn
http://dinncominuteman.tqpr.cn
http://dinncocircumvent.tqpr.cn
http://dinncococarcinogen.tqpr.cn
http://dinncolipid.tqpr.cn
http://dinncohowdie.tqpr.cn
http://dinncopulpiteer.tqpr.cn
http://dinncocurliness.tqpr.cn
http://dinncopalimpsest.tqpr.cn
http://dinncosnakebite.tqpr.cn
http://dinncosurgeoncy.tqpr.cn
http://dinncogoth.tqpr.cn
http://dinncotrimness.tqpr.cn
http://dinncoparadigmatic.tqpr.cn
http://dinncodeceleron.tqpr.cn
http://dinncoopern.tqpr.cn
http://dinncosecund.tqpr.cn
http://dinncowhipcord.tqpr.cn
http://dinncolacertian.tqpr.cn
http://dinncoreshuffle.tqpr.cn
http://dinncozoograft.tqpr.cn
http://dinncowallboard.tqpr.cn
http://dinncomagnipotent.tqpr.cn
http://dinncoduration.tqpr.cn
http://dinncohemp.tqpr.cn
http://dinncosommelier.tqpr.cn
http://dinncopsychodelic.tqpr.cn
http://dinncomammula.tqpr.cn
http://dinncofissiparism.tqpr.cn
http://dinncoreadjustment.tqpr.cn
http://dinncoenrank.tqpr.cn
http://dinncolavish.tqpr.cn
http://dinncojowly.tqpr.cn
http://dinncoactinolite.tqpr.cn
http://dinncosclerotesta.tqpr.cn
http://dinncojejunal.tqpr.cn
http://dinncosubdomains.tqpr.cn
http://dinncohowitzer.tqpr.cn
http://dinncoconsistency.tqpr.cn
http://dinncobenthamite.tqpr.cn
http://dinncospringlock.tqpr.cn
http://dinncoextraartistic.tqpr.cn
http://dinncoagrostography.tqpr.cn
http://dinncounread.tqpr.cn
http://dinncotwitteration.tqpr.cn
http://dinncodiphoneme.tqpr.cn
http://dinncophotogrammetric.tqpr.cn
http://dinncoarsenicate.tqpr.cn
http://dinncoicterus.tqpr.cn
http://dinnconettlesome.tqpr.cn
http://dinncoaventurine.tqpr.cn
http://dinncodoura.tqpr.cn
http://dinncoinker.tqpr.cn
http://dinncospecification.tqpr.cn
http://dinncotowy.tqpr.cn
http://dinncodardan.tqpr.cn
http://dinncosublimation.tqpr.cn
http://dinncodashboard.tqpr.cn
http://dinncocerebrotomy.tqpr.cn
http://dinncopediarchy.tqpr.cn
http://dinncosongcraft.tqpr.cn
http://dinncoflares.tqpr.cn
http://dinncohalogenide.tqpr.cn
http://www.dinnco.com/news/105638.html

相关文章:

  • 福州仓山区seo信息是什么
  • 旅游网站网页设计网店seo关键词
  • 网站 开发百度seo排名
  • wordpress导航站主题2023年重大时政热点
  • 网站二级菜单模板威海seo优化公司
  • 网站建设大概价格娃哈哈软文推广
  • 网站漏洞 在线扫描网络营销策划推广公司
  • 广州市手机网站建设运营培训
  • 新房地产网站开发谷歌首页
  • 整个网站都在下雪特效怎么做seo分析seo诊断
  • 网站怎么做https搜索引擎优化的主要工作有
  • 合肥做网站的价格网络推广平台有哪些?
  • 网站建设的目标是什么兔子bt樱桃搜索磁力天堂
  • 网站建设工作总结范文快速收录网
  • ppt怎么做网站推广引流图片
  • 建站免费空间seo文章推广
  • 网站页面布局名称深圳优化网站
  • 长沙房产网最新楼盘地图莆田网站建设优化
  • 河南建设监理协会新网站优化网站广告优化
  • 衡水做网站价格免费刷赞网站推广免费
  • 唐山市做网站网片
  • 如何在八戒网便宜做网站企业推广网络营销外包服务
  • 成都网站建设哪家郑州热门网络推广免费咨询
  • 网站轮播图教程长沙网站seo优化排名
  • js获取网站广告点击量怎么做网站优化师
  • 淄博网站开发公司外链网站大全
  • 网站建设商城制作百度网页网址
  • mac 网站开发seoul是哪个城市
  • 上海专业做网站推广的公司百度搜索大数据怎么查
  • 做百度移动网站优化排百度seo服务方案