Spring MVC中注解 @ModelAttribute
1、@ModelAttribute放在方法之上,在当前Control内的所有方法映射多个URL的请求,都会执行该方法
@ModelAttribute
public void itemsCommon(HttpServletRequest request,Model model){
model.addAttribute("common", "common111");
}
2、如果在请求链接中没有参数abc,塞入到model中的参数值为null
@ModelAttribute
public void itemsCommon(HttpServletRequest request,Model model,String abc){
model.addAttribute("common", abc);
}
3、和上述方法的 model.addAttribute("common", abc);效果相同
@ModelAttribute(value="common")
public String itemsCommon(HttpServletRequest request,Model model,String abc){
return abc;
}
4、如果不设置value值,则attribute的key值隐式设置为类型(首字母小写),如下理解为 model.addAttribute("string", abc)
如果返回类型为model,则为model类名的小写,如model.addAttribute("persion", abc)
@ModelAttribute
public String itemsCommon(HttpServletRequest request,Model model,String abc){
return abc;
}
5、@ModelAttribute和@RequestMapping可以同时放在一个方法上
6、@ModelAttribute可以放在参数前面
@RequestMapping("/testCommon")
public String itemsCommon(@ModelAttribute String abc){
return abc;
}
Spring MVC中注解 @ModelAttribute的更多相关文章
- Spring MVC中注解: @ModelAttribute 与@RequestParam区别
相关链接 : https://blog.csdn.net/huang343/article/details/77491096
- Spring MVC中注解的简介
参考网址: https://blog.csdn.net/a67474506/article/details/46361195 @RequestMapping映射请求 SpringMVC 使用 @Re ...
- Spring MVC 中 @ModelAttribute 注解的妙用
Spring MVC 中 @ModelAttribute 注解的妙用 Spring MVC 提供的这种基于注释的编程模型,极大的简化了 web 应用的开发.其中 @Controller 和 @Rest ...
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- Spring MVC中基于注解的 Controller
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
- Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法
Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...
- Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用
Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019 ...
- spring 以及 spring mvc 中常用注解整理
spring 以及 spring mvc 中常用注解整理 @RequestMapping(映射路径) @Autowired(注入 bean 对象) 例如: @Autowired private Bas ...
随机推荐
- [LeetCode#261] Graph Valid Tree
Problem: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair o ...
- [LeetCode#246] Missing Ranges Strobogrammatic Number
Problem: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked a ...
- bzoj3209
首先这道题目不难想到将答案转化为这种形式 2^s[2]*3*s[3]*…max*s[max] 这时候我们要分类讨论,设n的二进制位数为t 当1~n中二进制位数小于t时 我们可以直接用组合的知识,二进制 ...
- codeforces -- 283A
A. Cows and Sequence time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- java jdbc使用配置文件连接数据库:
java jdbc使用配置文件连接数据库: 创建后缀名为:.properties的文件,文件内容包括,数据库驱动.连接的数据库地址.用户名.密码…… 以Mysql为例创建config.properti ...
- javascript:void到底是个什么?
一般都是用作 实现 如下功能,当点击一个超链接的时候,不想出发超链接自带的动作,而触发自定义的js方法,一般与onclick 一起出现.如果不写void(0)点击超链接时候虽然调用js方法,但是也会出 ...
- iptables vpn
- hpuoj 问题 C: 善良的国王【最小生成树kurskal】
问题 C: 善良的国王 时间限制: 1 Sec 内存限制: 128 MB提交: 112 解决: 48[提交][状态][讨论版] 题目描述 很久很久以前,有一个贫困的国家,这个国家有一个善良爱民的国 ...
- history对象back()、forward()、go()
history对象back().forward().go()方法history.back() 功能:加载历史列表中的前一个URL(后退). 语法:history.back() 调用该方法的效果等价于点 ...
- golang 学习笔记
golan 声明的变量必须要用到? 语法 a,b:=2323; b为 bool 类型 结构体的赋值 需要用到逗号分隔字段 并且最后一个字段后也必须加上逗号 这和 JavaScript 的对象不一样哦 ...