博客
关于我
SpringMVC__表单回显以及@ModelAttribute
阅读量:84 次
发布时间:2019-02-26

本文共 739 字,大约阅读时间需要 2 分钟。

通过Model方式

如果使用对象去接收客户端传来的数据,那么对象默认会被自动放到model中,在前端页面可以直接使用对象中的数据。
@ModelAttribute(“stu”)是给这个需要回传的对象取别名,如果不使用,则以该对象名首字母小写为名,如Student对象不使用@ModelAttribute(“stu”)就是student;使用了就用stu;

@RequestMapping(value="/selIndex",method=RequestMethod.GET)	public String selIndex(@ModelAttribute("stu") Student stu) {		// TODO Auto-generated method stub		System.out.println("stu:"+stu);		return "index";	}

配置全局变量在方法上加上注解:@ModelAttribute(“xxx”)

每一次进入controller都会执行,全局变量

@ModelAttribute("st")	public Student polIndex() {		// TODO Auto-generated method stub		Student stu = new Student("zsl","ooo");		System.out.println("每次都会执行:"+stu);		return stu;	}

页面jsp:

111${student.name}

222${student.stuId}

33${stu.name}

44${stu.stuId}

55${st.name}

55${st.stuId}

转载地址:http://kyik.baihongyu.com/

你可能感兴趣的文章
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>