首页 > 其他 > 详细

Sping 补充完成修改功能

时间:2019-06-29 17:07:20      阅读:80      评论:0      收藏:0      [点我收藏+]

1.视图层完整示例

	<form action="#" th:action="@{/update/{id}(id=${user.id})}" th:object="${user}" method="post" >
		<label for="name" >姓名</label>
		<input type="text" th:field="*{name}" id="name" placeholder="Name" >
		
		<p th:if="${#fields.hasErrors(‘name‘)}" th:errors="*{name}" ></p>
		
		<label for="age">年龄</label>
		<input type="text" th:field="*{age}"   id="age" placeholder="age" name="age">
		
		<p th:if="${#fields.hasErrors(‘age‘)}" th:errors="*{age}"></p>
		
		<label for="email">邮箱</label>
		<input type="text" th:field="*{email}" id="email" placeholder="Email">
		
		<p th:if="${#fields.hasErrors(‘email‘)}" th:errors="*{email}" ></p>
		
		<input type="submit" value="修改">
	</form>

  2.控制器层代码

	@PostMapping("/edit/{id}")
	public String editUser(@Valid User user,BindingResult bindingResult) {
		
		if(bindingResult.hasErrors()) {
			return "update-user";
		}
		return "update-user";
	}

动图示例

技术分享图片

Sping 补充完成修改功能

原文:https://www.cnblogs.com/max-hou/p/11107095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!