【Spring】抽丝剥茧SpringMVC-ModelAttribute使用方法

5G Multicast/Broadcast Services(MBS) (七) MBS广播DRX 当处于RRC_IDLE或RRC_INACTIVE或RRC_CONNECTED 状态时,如果为 G-RNTI 配置了broadcast DRX,则允许MAC entity使用broadcast DRX 操作不连续地监听此G-RNTI的PDCCH;此 G-RNTI 的 drx-onDurationTimerPTM 或 drx-InactivityTimerPTM 正在运行的时间,也就是。long DRX周期drx-LongCycle-PTM和drx-StartOffset-PTM定义DRX周期开始的子帧。 阅读详情

本文源码基于SpringMVC 5.2.7

@ModelAttribute 

    @ModelAttribute可以用在方法上,也可以用在参数上。当它用在方法上时候,SpringMVC会将其返回值绑定到model的属性上;当它用在参数上时候,SpringMVC会从model取出对应的属性传给该参数。

@Target({ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ModelAttribute {

	@AliasFor("name")
	String value() default "";

	@AliasFor("value")
	String name() default "";
	
	boolean binding() default true;
}
  • name() : 表示model中的属性名
  • binding() : 表示在参数解析时是否需要执行该属性的databind操作,默认是true

@ModelAttribute必须用在@Controller或者@ControllerAdvice注解的类上,否则SpringMVC收集不到。

用在方法上

@ModelAttribute用在方法上有2个作用:

1 绑定返回值到model的属性上,属性名或由@ModelAttribute,或根据方法返回类型生成。 例如:mypackage.OrderAddress 生成的名字是 orderAddress;List<mypackage.OrderAddress>生成的名字是orderAddressList。

2 如果@ModelAttribute所注解的方法上没有@RequestMapping注解,那么该方法将在请求的处理方法前执行。除了返回值将绑到model上,开发者还可以对model进行一些处理

示例一  没有@RequestMapping,不指定name

定义一个测试类

public class TestModelAttribute {

    private String  testName;

    private String testSource;


    public String getTestName() {
        return testName;
    }

    public void setTestName(String testName) {
        this.testName = testName;
    }

    public String getTestSource() {
        return testSource;
    }

    public void setTestSource(String testSource) {
        this.testSource = testSource;
    }
}

添加一个@ModuleAttribute注解的方法,@ModuleAttribute没有指定name,预期结果是model中增加一个属性,属性名根据TestModelAttribute类名生成得到

@ControllerAdvice
public class DemoControllerAdvice {


    @ModelAttribute
    public TestModelAttribute testInitModel() {
        TestModelAttribute result = new TestModelAttribute();
        result.setTestName("test");
        result.setTestSource("h5");
        return result;
    }

}

运行结果:model里面增加了属性名为"testModelAttribute"的属性

示例二  没有@RequestMapping,通过ModelMap直接向model添加更多的属性

@ControllerAdvice
public class DemoControllerAdvice {


    @ModelAttribute
    public void testInitModel(ModelMap model) {
        model.put("test1", "value1");
        model.put("test2", "value2");
        model.put("test3", "value3");
    }

}

 

用在参数上

     @ModelAttribute用在参数上主要用来进行参数解析,@ModelAttribute对应的参数解析器org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor。过程是将model中name对应的对象赋值给参数,如果该name没有被设置"bindingDisabled",那么将从reques取得数据绑定到参数对象中。

    @ModelAttribute在参数上非必须,即便没有@ModelAttribute注解,只要参数类型是非简单类型,SpringMVC的参数解析器ServletModelAttributeMethodProcessor也会执行上述操作,只不过此时属性name就只能根据参数类型生成。

示例一 有注解@ModelAttribute,并指定name

先在testInitModel中指定name

@ModelAttribute(name = "test")
    public TestModelAttribute testInitModel() {
        TestModelAttribute result = new TestModelAttribute();

        result.setTestName("testName");
        result.setTestSource("H5");

        return result;
    }

在请求的处理方法中增加参数TestModelAttribute,添加@ModelAttribute注解并指定name

@Controller
@RequestMapping("/focuse")
public class DemoController {

    @ResponseBody
    @RequestMapping("hello")
    public String hello(@ModelAttribute(name = "test") TestModelAttribute input) {
        return "hello world!";
    }

}

运行结果-input值来源于model中属性名为"test"的对象

 

示例二 没有注解@ModelAttribute,请求指定参数testName

请求的处理方法上增加TestModelAttribute参数,但是没有注解@ModelAttribute

@Controller
@RequestMapping("/focuse")
public class DemoController {

    @ResponseBody
    @RequestMapping("hello")
    public String hello(TestModelAttribute input) {
        return "hello world!";
    }

}

请求指定参数testName=WithoutAnnotation:127.0.0.1:8080/focuse/hello?testName=WithoutAnnotation

 

总结

在方法上使用场景

场景方法是否有@RequestMapping是否指定name效果
方法上没有指定

在调用请求处理方法前,往model添加指定name的属性,

并根据注解@ModelAttribute的binding属性设置该属性对应的参数是否需要绑定数据

没有不指定

在调用请求处理方法前,往model添加属性,属性的名字根据方法返回类型生成,

并根据注解@ModelAttribute的binding属性设置该属性是否需要绑定数据

有指定

在调用请求处理方法之后,往model添加指定name的属性,

并根据注解@ModelAttribute的binding属性设置该属性是否需要绑定数据

有不指定

在调用请求处理方法之后,往model添加属性,属性的名字根据方法返回类型生成,

并根据注解@ModelAttribute的binding属性设置该属性是否需要绑定数据

在参数上使用场景

场景是否有注解@ModelAttribute是否指定name效果
参数上没有/

1. 从model取出属性赋值给该参数,属性的名字根据参数类型生成,如果model中没有则根据参数类型创建对象。

2. 根据model中该属性的绑定设置确定是否对参数的对象执行数据绑定

 

有指定

1. 从model取出属性赋值给该参数,属性的名字根据参数类型生成,如果model中没有则根据参数类型创建对象。

2. 根据注解@ModelAttribute的binding属性设置是否需要绑定数据

3. 根据model中该属性的绑定设置确定是否对参数的对象执行数据绑定

有不指定

1. 从model取出属性赋值给该参数,属性的名字根据参数类型生成,如果model中没有则根据参数类型创建对象。

2. 根据注解@ModelAttribute的binding属性设置是否需要绑定数据

3. 根据model中该属性的绑定设置确定是否对参数的对象执行数据绑定



上一篇 参数解析器HandlerMethodArgumentResolver

下一篇 返回处理器HandlerMethodReturnValueHandler

再下一篇 异步请求WebAsyncManager

 

 

3、固定翼无人机模型解析 本文详细解析了固定翼无人机的动力学模型与纵向模型,涵盖位置、速度、角度及角速度的变化率方程,并介绍了力和力矩的计算方法以及气动系数的表达式。通过关键参数分析,探讨了速度、迎角和倾斜角对飞行性能的影响。文章还展示了模型在编队飞行和任务规划中的应用,并提出了参数优化与先进控制策略等优化思路,为无人机飞行控制系统设计提供了理论基础。 阅读详情

相关推荐

HR离职预测模型实战:可解释、可干预、可落地的三层架构

员工离职预测本质上是组织健康度的早期诊断技术,其核心原理在于从行为、心理与结构数据中识别稳定性衰减信号。该技术的价值不仅在于提升预测准确率,更在于将模糊的‘人才风险’转化为可归因、可干预的具体因子,如工龄阶段、满意度落差、薪酬分位数等。典型应用场景覆盖HRBP主动留任、业务部门梯队预警及HRIS系统智能升级。本文聚焦于构建具备业务可解释性与操作闭环能力的离职预警模型,深度融合HR工作流与机器学习工程实践,尤其强调逻辑回归基线、特征业务化重构及三层递进式架构设计。

赵士杰的博客 387

@ModelAttribute 获取方法参数值中的坑

通过@ModelAttribute注解在方法参数上,获取请求中的值,注意所注解的参数是否有无参构造函数。下面思考一个问题,@ModelAttribute所注解的参数到底是必填还是非必填。 public void getTest(@ModelAttribute("test") Byte test){...} 复制代码在上面方法中,如果不传test参数,会报一个错误,错误提示如下. Request p...

weixin_34344403的博客 1463

VIVADO中的IP核在MATLAB中仿真

VIVADO中的IP核在MATLAB中仿真项目简述VIVADO建立FFT IP核MATLAB调用FFT IP核 项目简述 我们都会用MATLAB进行算法验证,但是经常会发现如果VIVADO中调用了IP核,那么最终会发现VIVADO与MATLAB之间的数据不可以统一的对应起来。那么,MATLAB验证的效果就会大大下降,那么可不可以想办法将VIVADO中的IP核封装成一个函数在MATLAB中调用呢?答案是可以的。这篇博客主要以FFT的IP核为例讲解封装成一个函数并且成功在MATLAB中调用。 本次实验所使用的软

zhangningning1996的博客 6992

Java中使用注解校验参数

一、参数校验的注解 Java中参数校验的注解来自三方面,分别是 javax.validation:validation-api,对应包javax.validation.constraints org.springframework:spring-context,对应包org.springframework.validation org.hibernate:hibernate-validator,对应包org.hibernate.validator.constraints 1.啊 validatio

BruceBupt的博客 1万+

软件工程:数据字典

数据字典

永远怀着至诚之心拥抱世界 4275

广东省低应变题库

11.按《建筑地基基础检测规范》DBJ/T15-60-2019的规定,采用低应变法对混凝土预制桩进行检测时,地基基础设计等级为甲级的桩基工程抽检桩数不应少于总桩数的30%,其余桩基工程抽检桩数不应少于总桩数的20%,且不得少于10根;16.按《建筑地基基础检测规范》DBJ/T15-60-2019的规定,当对某桩的桩身完整性判定为III类时,可认为该桩不满足验收条件,不用进一步确定该桩桩身缺陷对桩身结构承载力的影响程度。2.地基基础检测所用计量器具均应在检定(校准、验证)的有效期内,性能符合相关技术要求。

ZShy001238的博客 319

系统调用得到函数的参数

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34071713的博客 257

分享一份小度在家1C系列NV2101刷机保姆级教程,轻松解锁第三方应用!(内含详细教程、刷机工具和救砖等工具)

分享一份小度在家1C系列NV2101刷机保姆级教程,轻松解锁第三方应用!(内含详细教程、刷机工具和救砖等工具)

XiaoqiangClub的博客 7171

深度解析 Spring MVC `@ModelAttribute` 注解

Spring MVC @ModelAttribute 摘要 @ModelAttribute 是 Spring MVC 核心注解,用于模型数据管理,提供两种使用方式: 方法级别:在控制器方法执行前预填充模型数据,可添加公共属性或特定数据 参数级别:自动绑定请求参数到命令对象,支持通过binding属性控制绑定行为 源码层面主要通过ModelAttributeMethodProcessor处理: 方法级别由RequestMappingHandlerAdapter统一调用 参数级别包含创建对象、数据绑定、验证等完

csdn_tom_168的博客 2047

1553B总线介绍及其硬件方案设计

军用1553B总线 1.简介 简单介绍可参考(https://blog.youkuaiyun.com/ScilogyHunter/article/details/108444231)博主写的很详细。 1553B总线是MIL-STD-1553总线的简称,其中B就是BUS,MIL-STD-1553B总线是飞机内部时分制命令/响应式多路复用数据总线。1553B数据总线标准是20世纪70年代由美国公布的一种串行多路数据总线标准。1553B总线能挂31个远置终端,1553B总线采用指令/响应型通信协议,它有三种终端类型: BC:

小幽余生不加糖 1万+

模型瘦身术:YOLOv5无损剪枝实战教程

本文介绍了一种YOLOv5模型的无损剪枝方法,通过"稀疏训练+结构化剪枝+微调"的流程,在不损失精度的前提下显著减小模型尺寸并提升推理速度。具体步骤包括:1)稀疏训练给参数排优先级;2)裁剪不重要通道;3)微调恢复精度;4)验证效果。实战部分详细展示了从环境搭建到剪枝实现的完整流程,并分析了剪枝后在边缘设备部署、实时检测等场景的优势。该方法可使YOLOv5s模型从14MB缩减至2-3MB,推理速度提升30%-50%,适用于资源受限设备的轻量化部署需求。

LXY_LOVE36的博客 104

[Spring MVC] - SpringMVC的各种参数绑定方式

SpringMVC的各种参数绑定方式 1. 基本数据类型(以int为例,其他类似):Controller代码: @RequestMapping("saysth.do") public void test(int count) { } 表单代码: <form action="saysth.do" method="post"> <input ...

weixin_30389003的博客 659

QT-Creator安装教程(windows)

本文介绍了Qt的下载安装步骤:1)通过镜像源下载安装包;2)运行exe文件时使用命令行参数指定镜像地址;3)在安装过程中选择路径和自定义安装组件,包含QT5和QT6版本的详细安装说明;4)安装后可继续添加扩展包或卸载组件。重点提示了QT6必须勾选的关键组件,并提供了组件管理的操作方法。

qq_53545309的博客 3107

【Spring】抽丝剥茧SpringMVC-目录

最近记录SpringMVC处理请求时的路径,汇总一下 DispatcherServlet RequestMappingHandlerMapping RequestMappingHandlerAdapter 参数解析器HandlerMethodArgumentResolver ModelAttribute使用方法 返回处理器HandlerMethodReturnValueHandler 异步请求WebAsyncManager HandlerExceptionResolver

beFocused的博客 343

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 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")

从原理层面掌握@ModelAttribute的使用(核心原理篇)【享学Spring MVC】

前言 Spring MVC提供的基于注释的编程模型,极大的简化了web应用的开发,我们都是受益者。比如我们在@RestController注解的组件上用@RequestMapping、@ExceptionHandler等注解来表示请求映射、异常处理等等。 使用这种注解的方式来开发控制器我认为最重要的优势是: 灵活的方法签名(入参随意写) 不必继承基类 不必实现接口 总之一句话:灵活性非常强,耦...

架构师:通透,才能写出好代码! 4983

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

SpringMVC 中的数据绑定如何使用 @ModelAttribute 注解

SpringMVC 是一个基于 Spring 框架的 Web 框架,它提供了一种简单、灵活的方式来开发 Web 应用程序。在开发 Web 应用程序时,我们需要将用户提交的数据绑定到我们的 Java 对象上。SpringMVC 提供了多种方式来实现数据绑定,其中一种方式是使用 @ModelAttribute 注解。本文将介绍 @ModelAttribute 注解的使用方法,并通过示例代码演示如何在 SpringMVC 中使用 @ModelAttribute 注解来进行数据绑定。

程序猿徐师兄的博客 294

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Spring 之请求参数解析原理(实体类传参封装解析)

Spring 之请求参数解析原理(实体类传参解析) 之前实习的时候有做一个需要反射执行类中方法的组件,对该方法支持的参数类型的映射与解析当时考虑了很多参数类型, 参数类型有 普通类型 数组 实体类 泛型 等更多组合的复杂类型,对于反射执行的方法若重载方法很多,其实是需要确定参数类型来找到对应执行的方法 那么在Spring项目中,对于传参,其实也是可以直接以实体类的形式传参,就很好奇,其是怎么做的?所以看了看源码,分析记录一下 关于Spring的核心元素 DispatchServlet 请查看

weixin_42272869的博客 3661

@ModelAttribute用法详解

@ModelAttribute用法详解 在学习SpringMVC的过程中,关于@ModelAttribute的使用方法一度遇到一些奇怪的问题,在深入研究源码之后,基本上弄清楚了其内部实现的原理。对于自己的理解有误区的地方进行了纠正,现进行总结如下: @ModelAttribute主要有如下两个功能: 1绑定请求参数到实体对象(表单的命令对象):一是将请求参数的输入封装到POJO对象中...

m0_37912407的博客 2117

@ModelAttribute(“ “)注解在方法参数中的作用

带@ModelAttribute创建的参数对象会被添加到Model对象中。注解在参数上时,可以从Form表单或URL参数中获取参数并绑定到model中。 <div class="logo f-l"> <a href="${ctx}/index/text.do?abc=123" title="中林logo"><img src="${pageContext.request.contextPath}/images/zl2-01.gif" /></a

wgp's blog 1908

[Spring MVC]之@ModelAttribute注解的用法

注解方法 在同一个控制器中,注解了@ModelAttribute的方法实际上会在@RequestMapping方法之前被调用。 注解无返回值方法 import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.a...

qq_42777577的博客 270

Spring MVC @ModelAttribute详解

如果配置了一个可以将String类型的账户值转换成Account类型实例的转换器Converter,那么上面这段代码就可以工作的很好,而不需要再额外写一个@ModelAttribute方法。@ModelAttribute方法通常被用来填充一些公共需要的属性或数据,比如一个下拉列表所预设的几种状态,或者宠物的几种类型,或者去取得一个HTML表单渲染所需要的命令对象,比如Account等。@ModelAttribute标注既可以被用在方法上,也可以被用在方法参数上。...

daobuxinzi的博客 9628

SpringMVC数据校验

1.JSR 303 校验框架 因为Spring的LocalValidatorFactroyBean既实现了 Spring的Validator接口,也实现了 JSR 303的Validator接口,因此我们介绍一个JSR303 JSR 303 JSR 303是Java为Bean数据合法性校验提供的标准的框架,它已经包含在JavaEE6.0中 JSR 303通过在Bean属性上标注类似于@NotNull、@Max等标准的注解指定校验规则,并通过标准的验证接口对Bean进行验证 注解 功能说明

路在何方 792

Spring 注解面面通 之 @ModelAttribute 模型属性绑定全解

  @ModelAttribute用于将方法参数或返回值绑定到Model属性上,并公开给Web视图。支持使用@RequestMapping注释的Controller类。   注解解析   ① value:     待绑定到Model属性的键名称。     默认Model属性键名称根据非限定类名从声明的属性类型(即方法参数类型或方法返回类型)推断而来:     mypackage.OrderAddress类型对应的键名称是orderAddress 。     List<mypackage.OrderAd

键盘上流淌的日子 3904

springboot2.3以上validate参数校验

1、jar <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> &

qq_38205881的博客 619

@ModelAttribute在方法上部和方法参数体中不同之处

首先是放在方法上 1 没有返回值 为void  应该是无论请求什么接口 会率先执行 @ModelAttribute public void populateModel(ModelMap model) { model.addAttribute("attributeName", "123"); } 2  不指定指定属性名称,方法返回一个对象,相当于model.addAttribute("user...

Wuhaotian1996的博客 1916

@ModelAttribute用法总结

@ModelAttribute     @ModelAttribute主要的作用是将数据添加到模型对象中,用于视图页面显示。@ModelAttribute注释的位置不同,和其他注解一起使用时有很多种用法。 @ModelAttribute注解在方法上。@ModelAttribute注解的方法会在Controller每个方法执行前被调用。这个有点类似于Juni...

yue_xx的博客 2万+
上一篇: 【Spring】抽丝剥茧SpringMVC-SessionAttributes机制
下一篇: 【Spring】抽丝剥茧SpringMVC-ContentNegotiationManager
北堂桓禧
博客等级 码龄10年 23粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值