Spring ModelAttribute注解失效原因

public String test(@RequestParam(value = "test") @ModelAttribute("test") String plateId)
通过实验,RequestParam和ModelAttribute注解互斥,即添加了RequestParam注解会导致ModelAttribute注解不生效,
只能使用Thymeleaf的Param命名空间 进行访问了。。。。。


Thymeleaf官方文档:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#web-context-namespaces-for-requestsession-attributes-etc.


2021-9-9 更新
ModelAttribute注解的使用方式是 方法不存在 RequestMapping 注解  并且  方法上存在 ModelAttribute 注解。才会进行后续处理

ModelAttribute注解的过滤定位:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#MODEL_ATTRIBUTE_METHODS

处理ModelAttribute和其他InitBinder注解的主入口的一个位置

方法签名位置:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#invokeHandlerMethod

org.springframework.web.method.annotation.ModelFactory#invokeModelAttributeMethods   这个方法签名就是处理 ModelAttribute注解的位置了

复制请注明出处,在世界中挣扎的灰太狼
原文地址:https://www.cnblogs.com/XingXiaoMeng/p/11495260.html