spring的form标签的使用

spring的form标签只能依赖于jsp使用,这里只是新见到的,稍微做下记录,也不纠结原理,就记录下用法

后端通过Model存数据

import org.springframework.ui.Model;

	//这里是点击修改后,查询到数据,去往修改页面,数据都绑定在model中
	@RequestMapping("/admin/to/edit/page")
	public String toEditPage(@RequestParam("adminId")Integer adminId,Model model) {
		
		Admin admin = adminService.getAdminById(adminId);
		model.addAttribute("admin",admin);
		
		return "admin-edit";
	}

通过form标签自动取数据填充

jsp页面导入form标签

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

form:form表单

form:form标签其实就是一个表单,只不过是spring的
modelAttribute:后端存入model的名称,这里存入的是一个对象
< form:input >:这里就是form的input标签
path:存入mode的对象的属性
cssClass:相当于class属性
最主要的是后端在model存入对象,前端form:form中的modelAttribute属性指定后端存入model对象的名称,form:input中的path指定这个对象的属性,可以拿到对应属性的值,cssClass指定class,直接跳转过来以后,属性就会自动填充

						<form:form action="admin/update.html" method="post" modelAttribute="admin">
							<form:hidden path="id"/>
							<div class="form-group">
								<label for="exampleInputPassword1">登陆账号</label>
								<form:input path="loginAcct" cssClass="form-control" />
							</div>
							<div class="form-group">
								<label for="exampleInputPassword1">登录密码</label>
								<form:input path="userPswd" cssClass="form-control" />
							</div>
							<div class="form-group">
								<label for="exampleInputPassword1">用户昵称</label>
								<form:input path="userName" cssClass="form-control" />
							</div>
							<div class="form-group">
								<label for="exampleInputEmail1">邮箱地址</label>
								<form:input cssClass="form-control" path="email" />
							</div>
							<button type="submit" class="btn btn-success">
								<i class="glyphicon glyphicon-edit"></i> 更新
							</button>
							<button type="reset" class="btn btn-danger">
								<i class="glyphicon glyphicon-refresh"></i> 重置
							</button>
						</form:form>

没有任何操作,跳转过来,它就应经自动填充好了
在这里插入图片描述

其它用法借鉴地址

夏末、初秋的博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值