资讯专栏INFORMATION COLUMN

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

wdzgege / 3579人阅读

摘要:虽然它不是必须,但是它是个很好的辅助官方解释首先看看官方的对它怎么说它将方法参数方法返回值绑定到的里面。解析注解标注的方法参数,并处理标注的方法返回值。

每篇一句

</>复制代码

  1. 我们应该做一个:胸中有蓝图,脚底有计划的人
前言

Spring MVC提供的基于注释的编程模型,极大的简化了web应用的开发,我们都是受益者。比如我们在@RestController标注的Controller控制器组件上用@RequestMapping@ExceptionHandler等注解来表示请求映射、异常处理等等。
使用这种注解的方式来开发控制器我认为最重要的优势是:

灵活的方法签名(入参随意写)

不必继承基类

不必实现接口

==总之一句话:灵活性非常强,耦合度非常低。==

在众多的注解使用中,Spring MVC中有一个非常强大但几乎被忽视的一员:@ModelAttribute。关于这个注解的使用情况,我在群里/线下问了一些人,感觉很少人会使用这个注解(甚至有的不知道有这个注解),这着实让我非常的意外。我认为至少这对于"久经战场"的一个老程序员来说这是不应该的吧。

不过没关系,有幸看到此文,能够帮你弥补弥补这块的盲区。
@ModelAttribute它不是开发必须的注解(不像@RequestMapping那么重要),so即使你不知道它依旧能正常书写控制器。当然,正所谓没有最好只有更好,倘若你掌握了它,便能够帮助你更加高效的写代码,让你的代码复用性更强、代码更加简洁、可维护性更高。

这种知识点就像反射、就像内省,即使你不知道它你完全也可以工作、写业务需求。但是若你能够熟练使用,那你的可想象空间就会更大了,未来可期。虽然它不是必须,但是它是个很好的辅助~

@ModelAttribute官方解释

首先看看Spring官方的JavaDoc对它怎么说:它将方法参数/方法返回值绑定到web viewModel里面。只支持@RequestMapping这种类型的控制器哦。它既可以标注在方法入参上,也可以标注在方法(返回值)上。

但是请注意,当请求处理导致异常时,引用数据和所有其他模型内容对Web视图不可用,因为该异常随时可能引发,使Model内容不可靠。因此,标注有@Exceptionhandler的方法不提供对Model参数的访问~

</>复制代码

  1. // @since 2.5 只能用在入参、方法上
  2. @Target({ElementType.PARAMETER, ElementType.METHOD})
  3. @Retention(RetentionPolicy.RUNTIME)
  4. @Documented
  5. public @interface ModelAttribute {
  6. @AliasFor("name")
  7. String value() default "";
  8. // The name of the model attribute to bind to. 注入如下默认规则
  9. // 比如person对应的类是:mypackage.Person(类名首字母小写)
  10. // personList对应的是:List 这些都是默认规则咯~~~ 数组、Map的省略
  11. // 具体可以参考方法:Conventions.getVariableNameForParameter(parameter)的处理规则
  12. @AliasFor("value")
  13. String name() default "";
  14. // 若是false表示禁用数据绑定。
  15. // @since 4.3
  16. boolean binding() default true;
  17. }
基本原理

我们知道@ModelAttribute能标注在入参上,也可以标注在方法上。下面就从原理处深入理解,从而掌握它的使用,后面再给出多种使用场景的使用Demo
和它相关的两个类是ModelFactoryModelAttributeMethodProcessor

</>复制代码

  1. @ModelAttribute缺省处理的是Request请求域,Spring MVC还提供了@SessionAttributes来处理和Session域相关的模型数据,详见:从原理层面掌握@SessionAttributes的使用【一起学Spring MVC】

关于ModelFactory的介绍,在这里讲解@SessionAttributes的时候已经介绍一大部分了,但特意留了一部分关于@ModelAttribute的内容,在本文继续讲解

ModelFactory

ModelFactory所在包org.springframework.web.method.annotation,可见它和web是强关联的在一起的。作为上篇文章的补充说明,接下里只关心它对@ModelAttribute的解析部分:

</>复制代码

  1. // @since 3.1
  2. public final class ModelFactory {
  3. // 初始化Model 这个时候`@ModelAttribute`有很大作用
  4. public void initModel(NativeWebRequest request, ModelAndViewContainer container, HandlerMethod handlerMethod) throws Exception {
  5. // 拿到sessionAttr的属性
  6. Map sessionAttributes = this.sessionAttributesHandler.retrieveAttributes(request);
  7. // 合并进容器内
  8. container.mergeAttributes(sessionAttributes);
  9. // 这个方法就是调用执行标注有@ModelAttribute的方法们~~~~
  10. invokeModelAttributeMethods(request, container);
  11. ...
  12. }
  13. //调用标注有注解的方法来填充Model
  14. private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer container) throws Exception {
  15. // modelMethods是构造函数进来的 一个个的处理吧
  16. while (!this.modelMethods.isEmpty()) {
  17. // getNextModelMethod:通过next其实能看出 执行是有顺序的 拿到一个可执行的InvocableHandlerMethod
  18. InvocableHandlerMethod modelMethod = getNextModelMethod(container).getHandlerMethod();
  19. // 拿到方法级别的标注的@ModelAttribute~~
  20. ModelAttribute ann = modelMethod.getMethodAnnotation(ModelAttribute.class);
  21. Assert.state(ann != null, "No ModelAttribute annotation");
  22. if (container.containsAttribute(ann.name())) {
  23. if (!ann.binding()) { // 若binding是false 就禁用掉此name的属性 让不支持绑定了 此方法也处理完成
  24. container.setBindingDisabled(ann.name());
  25. }
  26. continue;
  27. }
  28. // 调用目标的handler方法,拿到返回值returnValue
  29. Object returnValue = modelMethod.invokeForRequest(request, container);
  30. // 方法返回值不是void才需要继续处理
  31. if (!modelMethod.isVoid()){
  32. // returnValueName的生成规则 上文有解释过 本处略
  33. String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType());
  34. if (!ann.binding()) { // 同样的 若禁用了绑定,此处也不会放进容器里
  35. container.setBindingDisabled(returnValueName);
  36. }
  37. //在个判断是个小细节:只有容器内不存在此属性,才会放进去 因此并不会有覆盖的效果哦~~~
  38. // 所以若出现同名的 请自己控制好顺序吧
  39. if (!container.containsAttribute(returnValueName)) {
  40. container.addAttribute(returnValueName, returnValue);
  41. }
  42. }
  43. }
  44. }
  45. // 拿到下一个标注有此注解方法~~~
  46. private ModelMethod getNextModelMethod(ModelAndViewContainer container) {
  47. // 每次都会遍历所有的构造进来的modelMethods
  48. for (ModelMethod modelMethod : this.modelMethods) {
  49. // dependencies:表示该方法的所有入参中 标注有@ModelAttribute的入参们
  50. // checkDependencies的作用是:所有的dependencies依赖们必须都是container已经存在的属性,才会进到这里来
  51. if (modelMethod.checkDependencies(container)) {
  52. // 找到一个 就移除一个
  53. // 这里使用的是List的remove方法,不用担心并发修改异常??? 哈哈其实不用担心的 小伙伴能知道为什么吗??
  54. this.modelMethods.remove(modelMethod);
  55. return modelMethod;
  56. }
  57. }
  58. // 若并不是所有的依赖属性Model里都有,那就拿第一个吧~~~~
  59. ModelMethod modelMethod = this.modelMethods.get(0);
  60. this.modelMethods.remove(modelMethod);
  61. return modelMethod;
  62. }
  63. ...
  64. }

ModelFactory这部分做的事:执行所有的标注有@ModelAttribute注解的方法,并且是顺序执行哦。那么问题就来了,这些handlerMethods是什么时候被“找到”的呢???这个时候就来到了RequestMappingHandlerAdapter,来看看它是如何找到这些标注有此注解@ModelAttribute的处理器的~~~

RequestMappingHandlerAdapter

RequestMappingHandlerAdapter是个非常庞大的体系,本处我们只关心它对@ModelAttribute也就是对ModelFactory的创建,列出相关源码如下:

</>复制代码

  1. // @since 3.1
  2. public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean {
  3. // 该方法不能标注有@RequestMapping注解,只标注了@ModelAttribute才算哦~
  4. public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method ->
  5. (!AnnotatedElementUtils.hasAnnotation(method, RequestMapping.class) && AnnotatedElementUtils.hasAnnotation(method, ModelAttribute.class));
  6. ...
  7. // 从Advice里面分析出来的标注有@ModelAttribute的方法(它是全局的)
  8. private final Map> modelAttributeAdviceCache = new LinkedHashMap<>();
  9. @Nullable
  10. protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
  11. WebDataBinderFactory binderFactory = getDataBinderFactory(handlerMethod);
  12. // 每调用一次都会生成一个ModelFactory ~~~
  13. ModelFactory modelFactory = getModelFactory(handlerMethod, binderFactory);
  14. ...
  15. ModelAndViewContainer mavContainer = new ModelAndViewContainer();
  16. mavContainer.addAllAttributes(RequestContextUtils.getInputFlashMap(request));
  17. // 初始化Model
  18. modelFactory.initModel(webRequest, mavContainer, invocableMethod);
  19. mavContainer.setIgnoreDefaultModelOnRedirect(this.ignoreDefaultModelOnRedirect);
  20. ...
  21. return getModelAndView(mavContainer, modelFactory, webRequest);
  22. }
  23. // 创建出一个ModelFactory,来管理Model
  24. // 显然和Model相关的就会有@ModelAttribute @SessionAttributes等注解啦~
  25. private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {
  26. // 从缓存中拿到和此Handler相关的SessionAttributesHandler处理器~~处理SessionAttr
  27. SessionAttributesHandler sessionAttrHandler = getSessionAttributesHandler(handlerMethod);
  28. Class handlerType = handlerMethod.getBeanType();
  29. // 找到当前类(Controller)所有的标注的@ModelAttribute注解的方法
  30. Set methods = this.modelAttributeCache.get(handlerType);
  31. if (methods == null) {
  32. methods = MethodIntrospector.selectMethods(handlerType, MODEL_ATTRIBUTE_METHODS);
  33. this.modelAttributeCache.put(handlerType, methods);
  34. }
  35. List attrMethods = new ArrayList<>();
  36. // Global methods first
  37. // 全局的有限,最先放进List最先执行~~~~
  38. this.modelAttributeAdviceCache.forEach((clazz, methodSet) -> {
  39. if (clazz.isApplicableToBeanType(handlerType)) {
  40. Object bean = clazz.resolveBean();
  41. for (Method method : methodSet) {
  42. attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
  43. }
  44. }
  45. });
  46. for (Method method : methods) {
  47. Object bean = handlerMethod.getBean();
  48. attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
  49. }
  50. return new ModelFactory(attrMethods, binderFactory, sessionAttrHandler);
  51. }
  52. // 构造InvocableHandlerMethod
  53. private InvocableHandlerMethod createModelAttributeMethod(WebDataBinderFactory factory, Object bean, Method method) {
  54. InvocableHandlerMethod attrMethod = new InvocableHandlerMethod(bean, method);
  55. if (this.argumentResolvers != null) {
  56. attrMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
  57. }
  58. attrMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
  59. attrMethod.setDataBinderFactory(factory);
  60. return attrMethod;
  61. }
  62. }

RequestMappingHandlerAdapter这部分处理逻辑:每次请求过来它都会创建一个ModelFactory,从而收集到全局的(来自@ControllerAdvice)+ 本Controller控制器上的所有的标注有@ModelAttribute注解的方法们。
@ModelAttribute标注在多带带的方法上(木有@RequestMapping注解),它可以在每个控制器方法调用之前,创建出一个ModelFactory从而管理Model数据~

</>复制代码

  1. ModelFactory管理着Model,提供了@ModelAttribute以及@SessionAttributes等对它的影响

同时@ModelAttribute可以标注在入参、方法(返回值)上的,标注在不同地方处理的方式是不一样的,那么接下来又一主菜ModelAttributeMethodProcessor就得登场了。

ModelAttributeMethodProcessor

从命名上看它是个Processor,所以根据经验它既能处理入参,也能处理方法的返回值:HandlerMethodArgumentResolver + HandlerMethodReturnValueHandler。解析@ModelAttribute注解标注的方法参数,并处理@ModelAttribute标注的方法返回值。

==先看它对方法入参的处理(稍显复杂):==

</>复制代码

  1. // 这个处理器用于处理入参、方法返回值~~~~
  2. // @since 3.1
  3. public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
  4. private static final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
  5. private final boolean annotationNotRequired;
  6. public ModelAttributeMethodProcessor(boolean annotationNotRequired) {
  7. this.annotationNotRequired = annotationNotRequired;
  8. }
  9. // 入参里标注了@ModelAttribute 或者(注意这个或者) annotationNotRequired = true并且不是isSimpleProperty()
  10. // isSimpleProperty():八大基本类型/包装类型、Enum、Number等等 Date Class等等等等
  11. // 所以划重点:即使你没标注@ModelAttribute 单子还要不是基本类型等类型,都会进入到这里来处理
  12. // 当然这个行为是是收到annotationNotRequired属性影响的,具体的具体而论 它既有false的时候 也有true的时候
  13. @Override
  14. public boolean supportsParameter(MethodParameter parameter) {
  15. return (parameter.hasParameterAnnotation(ModelAttribute.class) ||
  16. (this.annotationNotRequired && !BeanUtils.isSimpleProperty(parameter.getParameterType())));
  17. }
  18. // 说明:能进入到这里来的 证明入参里肯定是有对应注解的???
  19. // 显然不是,上面有说 这事和属性值annotationNotRequired有关的~~~
  20. @Override
  21. @Nullable
  22. public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
  23. // 拿到ModelKey名称~~~(注解里有写就以注解的为准)
  24. String name = ModelFactory.getNameForParameter(parameter);
  25. // 拿到参数的注解本身
  26. ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
  27. if (ann != null) {
  28. mavContainer.setBinding(name, ann.binding());
  29. }
  30. Object attribute = null;
  31. BindingResult bindingResult = null;
  32. // 如果model里有这个属性,那就好说,直接拿出来完事~
  33. if (mavContainer.containsAttribute(name)) {
  34. attribute = mavContainer.getModel().get(name);
  35. } else { // 若不存在,也不能让是null
  36. // Create attribute instance
  37. // 这是一个复杂的创建逻辑:
  38. // 1、如果是空构造,直接new一个实例出来
  39. // 2、若不是空构造,支持@ConstructorProperties解析给构造赋值
  40. // 注意:这里就支持fieldDefaultPrefix前缀、fieldMarkerPrefix分隔符等能力了 最终完成获取一个属性
  41. // 调用BeanUtils.instantiateClass(ctor, args)来创建实例
  42. // 注意:但若是非空构造出来,是立马会执行valid校验的,此步骤若是空构造生成的实例,此步不会进行valid的,但是下一步会哦~
  43. try {
  44. attribute = createAttribute(name, parameter, binderFactory, webRequest);
  45. } catch (BindException ex) {
  46. if (isBindExceptionRequired(parameter)) {
  47. // No BindingResult parameter -> fail with BindException
  48. throw ex;
  49. }
  50. // Otherwise, expose null/empty value and associated BindingResult
  51. if (parameter.getParameterType() == Optional.class) {
  52. attribute = Optional.empty();
  53. }
  54. bindingResult = ex.getBindingResult();
  55. }
  56. }
  57. // 若是空构造创建出来的实例,这里会进行数据校验 此处使用到了((WebRequestDataBinder) binder).bind(request); bind()方法 唯一一处
  58. if (bindingResult == null) {
  59. // Bean property binding and validation;
  60. // skipped in case of binding failure on construction.
  61. WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
  62. if (binder.getTarget() != null) {
  63. // 绑定request请求数据
  64. if (!mavContainer.isBindingDisabled(name)) {
  65. bindRequestParameters(binder, webRequest);
  66. }
  67. // 执行valid校验~~~~
  68. validateIfApplicable(binder, parameter);
  69. //注意:此处抛出的异常是BindException
  70. //RequestResponseBodyMethodProcessor抛出的异常是:MethodArgumentNotValidException
  71. if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
  72. throw new BindException(binder.getBindingResult());
  73. }
  74. }
  75. // Value type adaptation, also covering java.util.Optional
  76. if (!parameter.getParameterType().isInstance(attribute)) {
  77. attribute = binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType(), parameter);
  78. }
  79. bindingResult = binder.getBindingResult();
  80. }
  81. // Add resolved attribute and BindingResult at the end of the model
  82. // at the end of the model 把解决好的属性放到Model的末尾~~~
  83. // 可以即使是标注在入参上的@ModelAtrribute的属性值,最终也都是会放进Model里的~~~可怕吧
  84. Map bindingResultModel = bindingResult.getModel();
  85. mavContainer.removeAttributes(bindingResultModel);
  86. mavContainer.addAllAttributes(bindingResultModel);
  87. return attribute;
  88. }
  89. // 此方法`ServletModelAttributeMethodProcessor`子类是有复写的哦~~~~
  90. // 使用了更强大的:ServletRequestDataBinder.bind(ServletRequest request)方法
  91. protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
  92. ((WebRequestDataBinder) binder).bind(request);
  93. }
  94. }

模型属性首先从Model中获取,若没有获取到,就使用默认构造函数(可能是有无参,也可能是有参)创建,然后会把ServletRequest请求的数据绑定上来, 然后进行@Valid校验(若添加有校验注解的话),最后会把属性添加到Model里面

最后加进去的代码是:mavContainer.addAllAttributes(bindingResultModel);这里我贴出参考值:

如下示例,它会正常打印person的值,而不是null(因为Model内有person了~)
请求链接是:/testModelAttr?name=wo&age=10

</>复制代码

  1. @GetMapping("/testModelAttr")
  2. public void testModelAttr(@Valid Person person, ModelMap modelMap) {
  3. Object personAttr = modelMap.get("person");
  4. System.out.println(personAttr); //Person(name=wo, age=10)
  5. }

注意:虽然person上没有标注@ModelAtrribute,但是modelMap.get("person")依然是能够获取到值的哦,至于为什么,原因上面已经分析了,可自行思考。

下例中:

</>复制代码

  1. @GetMapping("/testModelAttr")
  2. public void testModelAttr(Integer age, Person person, ModelMap modelMap) {
  3. System.out.println(age); // 直接封装的值
  4. System.out.println("-------------------------------");
  5. System.out.println(modelMap.get("age"));
  6. System.out.println(modelMap.get("person"));
  7. }

请求:/testModelAttr?name=wo&age=10 输入为:

</>复制代码

  1. 10
  2. -------------------------------
  3. null
  4. Person(name=wo, age=10)

可以看到普通类型(注意理解这个普通类型)若不标注@ModelAtrribute,它是不会自动识别为Model而放进来的哟~~~若你这么写:

</>复制代码

  1. @GetMapping("/testModelAttr")
  2. public void testModelAttr(@ModelAttribute("age") Integer age, Person person, ModelMap modelMap) {
  3. System.out.println(age); // 直接封装的值
  4. System.out.println("-------------------------------");
  5. System.out.println(modelMap.get("age"));
  6. System.out.println(modelMap.get("person"));
  7. }

打印如下:

</>复制代码

  1. 10
  2. -------------------------------
  3. 10
  4. Person(name=wo, age=10)

请务必注意以上case的区别,加深记忆。使用的时候可别踩坑了~

==再看它对方法(返回值)的处理(很简单):==

</>复制代码

  1. public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
  2. // 方法返回值上标注有@ModelAttribute注解(或者非简单类型) 默认都会放进Model内哦~~
  3. @Override
  4. public boolean supportsReturnType(MethodParameter returnType) {
  5. return (returnType.hasMethodAnnotation(ModelAttribute.class) ||
  6. (this.annotationNotRequired && !BeanUtils.isSimpleProperty(returnType.getParameterType())));
  7. }
  8. // 这个处理就非常非常的简单了,注意:null值是不放的哦~~~~
  9. // 注意:void的话 returnValue也是null
  10. @Override
  11. public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
  12. ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
  13. if (returnValue != null) {
  14. String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
  15. mavContainer.addAttribute(name, returnValue);
  16. }
  17. }
  18. }

它对方法返回值的处理非常简单,只要不是null(当然不能是void)就都会放进Model里面,供以使用

总结

本文介绍的是@ModelAttribute的核心原理,他对我们实际使用有重要的理论支撑。下面系列文章主要在原理的基础上,展示各种各样场景下的使用Demo,敬请关注~

相关阅读

从原理层面掌握@SessionAttributes的使用【一起学Spring MVC】
从原理层面掌握@RequestAttribute、@SessionAttribute的使用【一起学Spring MVC】
从原理层面掌握@ModelAttribute的使用(使用篇)【一起学Spring MVC】

知识交流

==The last:如果觉得本文对你有帮助,不妨点个赞呗。当然分享到你的朋友圈让更多小伙伴看到也是被作者本人许可的~==

**若对技术内容感兴趣可以加入wx群交流:Java高工、架构师3群
若群二维码失效,请加wx号:fsx641385712(或者扫描下方wx二维码)。并且备注:"java入群" 字样,会手动邀请入群**

</>复制代码

  1. 若文章格式混乱或者图片裂开,请点击`:原文链接-原文链接-原文链接

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/76199.html

相关文章

  • 原理层面掌握@ModelAttribute使用使用)【一起Spring MVC

    摘要:和一起使用参照博文从原理层面掌握的使用一起学。至于具体原因,可以移步这里辅助理解从原理层面掌握的使用核心原理篇一起学再看下面的变种例子重要访问。 每篇一句 每个人都应该想清楚这个问题:你是祖师爷赏饭吃的,还是靠老天爷赏饭吃的 前言 上篇文章 描绘了@ModelAttribute的核心原理,这篇聚焦在场景使用上,演示@ModelAttribute在不同场景下的使用,以及注意事项(当然有些...

    BenCHou 评论0 收藏0
  • 原理层面掌握@RequestAttribute、@SessionAttribute使用一起S

    摘要:同时另外一个目的是希望完全屏蔽掉源生,增加它的扩展性。本文我以为例进行讲解,因为也是后推出的注解不管从使用和原理上都是一模一样的。作用从中取对应的属性值。 每篇一句 改我们就改得:取其精华,去其糟粕。否则木有意义 前言 如果说知道@SessionAttributes这个注解的人已经很少了,那么不需要统计我就可以确定的说:知道@RequestAttribute注解的更是少之又少。我觉得主...

    why_rookie 评论0 收藏0
  • 原理层面掌握@SessionAttribute使用一起Spring MVC

    摘要:见名之意,它是处理器,也就是解析这个注解的核心。管理通过标注了的特定会话属性,存储最终是委托了来实现。只会清楚注解放进去的,并不清除放进去的它的唯一实现类实现也简单。在更新时,模型属性与会话同步,如果缺少,还将添加属性。 每篇一句 不是你当上了火影大家就认可你,而是大家都认可你才能当上火影 前言 该注解顾名思义,作用是将Model中的属性同步到session会话当中,方便在下一次请求中...

    ARGUS 评论0 收藏0
  • 原理层面掌握HandlerMethod、InvocableHandlerMethod使用一起

    摘要:并且,并且如果或者不为空不为且不为,将中断处理直接返回不再渲染页面对返回值的处理对返回值的处理是使用完成的对异步处理结果的处理使用示例文首说了,作为一个非公开,如果你要直接使用起来,还是稍微要费点劲的。 每篇一句 想当火影的人没有近道可寻,当上火影的人同样无路可退 前言 HandlerMethod它作为Spring MVC的非公开API,可能绝大多数小伙伴都对它比较陌生,但我相信你对它...

    wawor4827 评论0 收藏0
  • 原理层面掌握HandlerMethod、InvocableHandlerMethod使用一起

    摘要:并且,并且如果或者不为空不为且不为,将中断处理直接返回不再渲染页面对返回值的处理对返回值的处理是使用完成的对异步处理结果的处理使用示例文首说了,作为一个非公开,如果你要直接使用起来,还是稍微要费点劲的。 每篇一句 想当火影的人没有近道可寻,当上火影的人同样无路可退 前言 HandlerMethod它作为Spring MVC的非公开API,可能绝大多数小伙伴都对它比较陌生,但我相信你对它...

    miya 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<