博客
关于我
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/

你可能感兴趣的文章
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
Mysql5.6主从复制-基于binlog
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
MySQL5.6的Linux安装shell脚本之二进制安装(一)
查看>>
MySQL5.6的zip包安装教程
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>