springMVC验证的hibernate validator 框架 的groups怎么用
1个回答
推荐于2016-04-19
展开全部
首先,在pom.xml中添加hibernate.validator的支持
[html] view plaincopy
<!-- hibernate.validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
表单提交页面user_add.jsp
[html] view plaincopy
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>add user</title>
</head>
<body>
<form:form id="form" method="post"
modelAttribute="validUserBean">
添加用户
<form:label path="account">账号:</form:label>
<form:input path="account" />
<form:errors path="account" />
<form:label path="password">密码:</form:label>
<form:input path="password" />
<form:errors path="password" />
<button type="submit">添加</button>
<button type="reset">重置</button>
<c:out value="${show}"></c:out>
</form:form>
</body>
</html>
[html] view plaincopy
<!-- hibernate.validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
表单提交页面user_add.jsp
[html] view plaincopy
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>add user</title>
</head>
<body>
<form:form id="form" method="post"
modelAttribute="validUserBean">
添加用户
<form:label path="account">账号:</form:label>
<form:input path="account" />
<form:errors path="account" />
<form:label path="password">密码:</form:label>
<form:input path="password" />
<form:errors path="password" />
<button type="submit">添加</button>
<button type="reset">重置</button>
<c:out value="${show}"></c:out>
</form:form>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询