Spring Framework源码(十三):SpringMVC之从ModelMap到页面渲染

SpringBoot2学习笔记03 三十二、请求处理- 【源码分析】 -各种类型参数解析原理 前面我们测试了SpringMVC底层的常用注解,很神奇,只要给参数位置标注这些注解,SpringMVC就会按照你的要求自动的在调用目标方法的时候帮这些参数确定好值,下面就可以使用了 但是确定值的过程以及源码是怎么写的,我们可以看一下,我们所有源码都是从DispatcherServlet开始,处理请求的入口,里面也会涉及到SpringMVC的核心组件 debug来到我们的doDispatch方法,前置的流程差不多过一下, mappedHand 阅读详情

    SpringMVC在调用了Controller的方法后会返回ModelAndView对象,这个对象会被传回DispatcherServlet的doDispatch方法中。接下来再调用以下的方法渲染页面:

processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException);
private void processDispatchResult(HttpServletRequest request, HttpServletResponse response,
			HandlerExecutionChain mappedHandler, ModelAndView mv, Exception exception) throws Exception {
                //view是否被正确设置的控制变量
		boolean errorView = false;
                //如果前面的过程发生异常
		if (exception != null) {
			//如果是ModelAndViewDefiningException异常
			if (exception instanceof ModelAndViewDefiningException) {
				logger.debug("ModelAndViewDefiningException encountered", exception);
				mv = ((ModelAndViewDefiningException) exception).getModelAndView();
			}
			//如果不是,继续处理这个请求处理异常
			else {
				Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null);
				mv = processHandlerException(request, response, handler, exception);
				errorView = (mv != null);
			}
		}

		//请求处理器是否返回了一个正确的view给渲染器
		if (mv != null && !mv.wasCleared()) {
			//开始渲染页面
			render(mv, request, response);
			if (errorView) {
				WebUtils.clearErrorRequestAttributes(request);
			}
		}
		//省略代码若干...
	}

     由上面的代码可以看出SpringMVC在检查请求处理过程中没有发生什么异常后就开始渲染页面了。

protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//将用户使用的Locale(区域语言信息)传给response
		Locale locale = this.localeResolver.resolveLocale(request);
		response.setLocale(locale);

		View view;
		//如果用户的controller的方法返回的是字符串即view name
		if (mv.isReference()) {
			// 查找view name对应的view并返回View对象
			view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
			if (view == null) {
				throw new ServletException("Could not resolve view with name '" + mv.getViewName() +
						"' in servlet with name '" + getServletName() + "'");
			}
		}
		//如果用户的controller的方法返回的是View对象则直接获取
		else {
			view = mv.getView();
			if (view == null) {
				throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a " +
						"View object in servlet with name '" + getServletName() + "'");
			}
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
		}
		//调用view的渲染函数
		try {
			view.render(mv.getModelInternal(), request, response);
		}
		catch (Exception ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '" +
						getServletName() + "'", ex);
			}
			throw ex;
		}
	}

     这里有两个地方我们需要注意下就是View对象的查找过程和View对象的render过程。这里我们以jsp的渲染举例说明:

protected View resolveViewName(String viewName, Map<String, Object> model, Locale locale,
			HttpServletRequest request) throws Exception {
		for (ViewResolver viewResolver : this.viewResolvers) {
			View view = viewResolver.resolveViewName(viewName, locale);
			if (view != null) {
				return view;
			}
		}
		return null;
	}

     看到这里我们立刻明白是在我们注册的ViewResolver中挨个试探性的处理这个viewName,试探的过程就是在IOC容器中找viewName对应的View类型的bean,如果类型匹配返回这个bean,如果不匹配则返回null。看到这个viewResolvers我们立刻想到DispatcherServlet中的initStrategies方法,里面用initViewResolvers(context)初始化了这个成员变量。那么什么事viewResolver呢?我们以jsp为例来看看:

<bean id="jspViewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/jsp/" />
		<property name="suffix" value=".jsp" />
		<property name="order" value="1" />
	</bean>

    这就是一个viewResolver,再来看看对应的InternalResourceView是怎么渲染的,它的render函数是在它的父类AbstractView中实现的。

        public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//创建整合后需要返回给浏览器的Model
		Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);
		//设置一些Response的头部信息
		prepareResponse(request, response);
		//渲染数据
		renderMergedOutputModel(mergedModel, getRequestToExpose(request), response);
	}

    InternalResourceView覆盖了父类的renderMergedOutputModel方法。

protected void renderMergedOutputModel(
			Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //将model中的数据设置到request(因为不见得所有数据都是通过request.setAttribute加入的)
		exposeModelAsRequestAttributes(model, request);
		//本类中的此函数是空函数,留给子类比如JstlView去实现自定义逻辑
		exposeHelpers(request);
		//设置跳转目的页面路径
		String dispatcherPath = prepareForRendering(request, response);
        //获取跳转控制器RequestDispatcher
		RequestDispatcher rd = getRequestDispatcher(request, dispatcherPath);
		if (rd == null) {
			throw new ServletException("Could not get RequestDispatcher for [" + getUrl() +
					"]: Check that the corresponding file exists within your web application archive!");
		}
                //决定跳转到另一个控制器即forward操作还是返回用户请求资源,
		//如果用户设置或配置INCLUDE_REQUEST_URI_ATTRIBUTE
		//属性或response已经提交数据则直接返回资源给用户
		if (useInclude(request, response)) {
			response.setContentType(getContentType());
			if (logger.isDebugEnabled()) {
				logger.debug("Including resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");
			}
			rd.include(request, response);
		}
                //携带request和response跳转到另一个控制器方法
		else {
			// Note: The forwarded resource is supposed to determine the content type itself.
			if (logger.isDebugEnabled()) {
				logger.debug("Forwarding to resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");
			}
			rd.forward(request, response);
		}
	}

        这一步完成后SpringMVC就基本上完成自己的使命了,当找到对应的url路径,springmvc就继续访问url对应的servlet,剩下的渲染工作就交由Servlet去处理了,所以由此我们不难看出,springmvc实际是在tomcat和servlet中间加了一层,处理request将浏览器传递的参数封装成model再由应用来加工处理这些数据后,再将这些数据传递给servlet让servlet将这些经过应用处理的数据在页面上表现出来,从而完成web请求,目的在于页面和数据分离即页面表现和业务逻辑的分离,使开发中可以集中精力处理业务逻辑提高开发效率。  

        Spring Transation和Spring JDBC我们就不具体分析了,感兴趣的看官可以自己下载份源码研究。Spring Framework的源码分析至此结束。

 

 

 

别怕,“卷积”其实很简单 首先给大家讲一个关于卷积的小故事:小明是杭州某互联网大厂的员工,每天996十分辛苦,但小明最近爱上了打台球,经常不在工位。这天,小明的主管让小明改一个需求,小明却到楼下找产品部小丽打台球去了,被主管发现,他非常气愤,扇了小明一巴掌(注意,这就是输入信号,脉冲)。于是小明脸上会渐渐地(贱贱地)鼓起来一个包,小明的脸就是一个系统,而鼓起来的包就是小明的脸对巴掌的响应。好,这样就和信号系统建立起来意义对应的联系。 阅读详情

相关推荐

电机控制-PMSM无感FOC控制(五)SVPWM过调制策略优化与谐波抑制

本文深入探讨了PMSM无感FOC控制中的SVPWM过调制策略优化与谐波抑制。针对电机高速运行时电压利用率不足的问题,分析了过调制技术的必要性,并详细阐述了分区过调制、谐波注入及闭环优化等主流策略,旨在提升电压利用率与抑制电流谐波,实现电机高性能控制。

convnet3designer的博客 354

Spring中Model、ModelMap及ModelAndView之间的区别

1. Model(org.springframework.ui.Model) Model是一个接口,包含addAttribute方法,其实现类是ExtendedModelMap。 ExtendedModelMap继承了ModelMap类,ModelMap类实现了Map接口。 public class ExtendedModelMap extends ModelMap implements M...

LSur_king的博客 506

处理图数据, 安装“Pytorch“ + 图神经网络开源框架“PyG “+ “ogb“使用

"OGB" OSError: [WinError 127] 找不到指定的程序。1.[遇到这类问题往往跟torch安装的工具包(如torch-sparse,torch-scatter,torch-cluster)版本没对应上有关](https://blog.csdn.net/weixin_42358688/article/details/117433691)2.[OGB使用环境安装与依赖](https://ogb.stanford.edu/docs/home/)Data Loaders3.[torch-geo

Fuguir™的博客 3703

SpringMVC将数据显示到前端的三种方式

SpringMVC将数据显示到前端的三种方式 1.通过Model将数据显示到前端 @RequestMapping("/ct2/hello") public String hello(@RequestParam("username") String name, Model model){ //封装要显示到视图中的数据 //相当于req.setAttribute("name",name); model.addAttribute("msg",nam

weixin_54101424的博客 1909

DFT知识点扫盲——DFT scan chain

实际在项目中synccell一般直接上ULVT,既然是SDF,就是带Scan接口的DFF,SN (set negtive)是低置位,RP(reset positive)是高复位,既没有SN也没有RP的就是无复位寄存器。1:定义:满足可测试性设计(DFT),将设计中所有的触发器连接到一条或者若干条链上,称为scan chain,将一个复杂的时序电路转换为简单的组合电路进行测试,这一步是在逻辑综合(DC)中实现。当SE=1当SI=1时,电路进入scan状态,当SI=0时,电路工作在normal状态。

笨蛋大乌龟的博客 4947

QCM6490平台DDR测试:从QDUTT配置到眼图分析的实战指南

本文详细介绍了QCM6490平台DDR测试的全流程,从QDUTT工具安装配置到眼图分析,提供了实战操作指南和常见问题解决方案。通过具体案例分享,帮助工程师掌握DDR测试技巧,确保内存稳定性,特别适用于物联网和边缘计算设备的开发调试。

weixin_33910191的博客 465

ssm框架搭建问题

可能这个问题,不是啥大问题 ,但是提供了一个解决问题的思路: 当你认为不会出现问题的地方,多半就是问题的根源当登陆界面 确认跳转到web-inf/view/admin/welcome.jsp时抛出500:浏览器端:HTTP Status 500 - Could not get RequestDispatcher for [/WEB-INF/view/admin/welcome.jsp/]: Che...

DEBUG 2491

ardupilot开发 --- MavLink 篇

ardupilot开发 --- MavLink 篇

记录老板的每次pua,分享领导每天的毒鸡汤... 4255

SpringMVC

SpringMVC——属于Spring Framework框架之一 Spring MVC 是 Spring 提供给 Web 应用的框架设计。Spring MVC 角色划分清晰,分工明细,并且和 Spring 框架无缝结合。作为当今业界最主流的 Web 开发框架,Spring MVC 已经成为当前最热门的开发技能,同时也广泛用于桌面开发领域 SpringBoot会默认将src/main/resources目录下的public、static作为静态文件夹,将templates作为模板文件夹。 注意: 默认的静

长不大的大灰狼 466

AI人工智能代理工作流 AI Agent WorkFlow:在股票市场预测中的应用

AI人工智能代理工作流 AI Agent WorkFlow:在股票市场预测中的应用 作者:禅与计算机程序设计艺术 / Zen and the Art of Computer Programming 关键词: AI Agent, W

AI天才研究院 862

可食用野生植物检测实战:基于YOLOv11的智能识别系统全流程指南

本文介绍了一种基于YOLOv11的可食用野生植物智能识别系统。该系统通过深度学习技术,能在0.2秒内精准识别植物是否可食用,准确率高达92%。文章详细阐述了从数据采集、标注到模型训练、验证的全流程,并开发了用户友好的Tkinter交互界面。该系统解决了户外探险和植物研究中植物识别的痛点,具有高精度、实时性和强泛化能力的特点,为户外安全提供了智能化解决方案。

FJN110的博客 166

Spring MVC 源码剖析

本文介绍了Spring MVC的Web配置及核心原理,主要包括:1)在web.xml中配置DispatcherServlet前端控制器,指定拦截规则(如*.action)和Spring配置文件位置;2)三种URL拦截方式对比,/方式需特殊处理静态资源;3)通过mvc:resources映射静态资源访问;4)中文乱码解决方案,包括POST请求过滤器和GET请求参数重编码。从Servlet角度分析了DispatcherServlet的继承体系,重点说明FrameworkServlet通过重写service()方

py_1990_04_20的博客 993

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Spring 源码分析(四) ——MVC(七)视图呈现

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)、博主微信(guyun297890152)、QQ技术交流群(183198395)。 from:https://my.oschina.net/kaywu123/blog/651842 DispatcherServlet 视图设计 前面分析了 Spring MVC 中的 M(Mod...

孤云博客 789

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot学习笔记2——源码分析(请求处理)

3、参数处理原理 HandlerMapping中找到能处理请求的Handler(Controller.method()) 为当前Handler 找一个适配器 HandlerAdapter; RequestMappingHandlerAdapter 适配器执行目标方法并确定方法参数的每一个值 1、HandlerAdapter 0 - 支持方法上标注@RequestMapping 1 - 支持函数式编程的 xxxxxx 2、执行目标方法 // Actually invok..

wellsaber的专栏 604

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SpringBoot---web-->>复杂参数Model、Map解析原理【用model、map操作请求参数】(5)

复杂参数Model、Map解析原理【用model、map操作请求参数】 早在Mvc阶段就知道,能用Model、Map存储数据然后在页面展示。现在探索的是拿到数据解析完参数,怎么把数据放在域中,展示在页面上。也就是如何完成渲染视图的过程的 控制器方法 这里把两个参数的required属性设置为不必须false(测试懒得改代码就要学会改属性),是因为在底下那个即将转发到这个控制器方法里面的请求内没有携带这两个名字的参数,required默认值是true,在访问请求时会报没有参数的错,所以设置为false

wowo 1881

1、InternalResourceViewResolver工作流程

项目结构: userinfocontroller.java package com.jd.userinfo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ...

方法属性类,一个都不会 804

springmvc交易接进来流程核心源码分析-21

1.以注解@Controller方式接进来 @Controller public class Controller1 { @RequestMapping("/hello") public String sayHello(String name){ System.out.println("Demo1控制器执行了...name:"+name); return "success"; } } ​ 调用栈如下: org.springframewo...

u012222011的博客 162

springmvc十六:视图解析

spring.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:m...

m0_37564426的博客 322

Servlet.service() for servlet [springMVC] in context with path [] threw exception [Could not get Req

在用tomcat部署应用的时候,特别是在一个新服务器上部署一个应用的时候,我们经常会遇到如下类似的错误: Servlet.service() for servlet [springMVC] in context with path [] threw exception [Could not get RequestDispatcher for [/LogisticsQuery.jsp]: Ch

hejisan的专栏 3万+

深入解析SpringBoot中的Model和Map参数处理机制

spring参数解析之model 和 map,从参数解析到如何设置到请求域全过程

Java领域优秀创作者 3193

JavaWeb-19-springmvc视图解析

Table of Contents 一:转发和重定向 1:转发:forward 2:重定向 二:视图解析 1:任何方法的返回值,都会包装ModelAndView对象 2:processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException); 3:调用render(mv, request, response);渲染页面 4:View与ViewResolver的关系; 5:根据视图名得到V

苍煜 767

springMVC源码分析--视图AbstractView和InternalResourceView(二)

上一篇博客 springMVC源码分析--视图View(一)中我们介绍了简单介绍了View的结构实现及运行流程,接下来我们介绍一下View的实现类做的处理操作。AbstractView实现了render方法,主要做的操作是将model中的参数和request中的参数全部都放到Request中,然后就转发Request就可以了。 @Override public void render(Map m

井底之蛙 5330

SpringBoot : Map、Model是怎么处理的? springboot第九期

文章目录小知识点示例为什么 Map和Model的数据会存放在request请求域中怎么把我们在map和model设置的东西给放到请求域里面? 小知识点 Map、Model(map、model里面的数据会被放在request的请求域 request.setAttribute)、Errors/BindingResult、RedirectAttributes( 重定向携带数据)、ServletResponse(response)、SessionStatus、UriComponentsBuilder、Servle

qq_47431361的博客 1125

【springboot】Servlet API参数解析(一)及√Model、Map类型源码分析(二)及自定义参数(三)

印证了(二)中发现的处理多种不同的参数时采用不同的methodProcessor(不同的resolver。这里有一个自学的思路,就是找实现方法时,如果只找到接口的抽象方法,可以ctrl+h(idea中快捷键)查看他与子类的继承or接口的实现关系,找到接口方法的实现类,就可以找到目标实现方法。我们加在方法上的参数Model和Map都是一个东西,因为数据都放到model中,然后最后都会被加到请求域中(request.addAttribute)——>>看源码这么久的意义。

m0_56249083的博客 588

Spring中Model、ModelMap、ModelAndView理解和具体使用总结

在了解这三者之前,需要知道一点:SpringMVC在调用方法前会创建一个隐含的数据模型,作为模型数据的存储容器, 成为”隐含模型”。 也就是说在每一次的前后台请求的时候会随带这一个背包,不管你用没有,这个背包确实是存在的,用来盛放我们请求交互传递的值;关于这一点,spring里面有一个注解: @ModelAttribute :被该注解修饰的方法,会在每一次请求时优先执行,用于接收前台js...

qq_21223653的博客 4万+
上一篇: Spring Framework源码(十二):SpringMVC之数据绑定、验证、转换
下一篇: ORM framework源码分析:引言之Java JDBC
闲庭细步
博客等级 码龄18年 304粉丝 86原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值