关于spring框架中的后台验证

我们可以在注册文件中加上这样一句话:

<bean

class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>

</bean>

在bean类中使用注解

package com.lovo.bean;


import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;


public class UserBean {
@NotEmpty(message="不能为空")
@Length(max=8,min=3,message="长度必须为3-8位之间")
private String username;
@NotEmpty(message="密码不能为空")
private String password;
public String getUsername() {
return username;
}


public void setUsername(String username) {
this.username = username;
}


public String getPassword() {
return password;
}


public void setPassword(String password) {
this.password = password;
}
}

在jsp中使用spring提交表单的功能:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags/form" %>


<html>
<head>
</head>
<body>
  <spring:form action="login2.spring" method="post" commandName="userBean">
name:<input type="text" name="username"><spring:errors delimiter="," path="username"></spring:errors><br />
pwd:<input type="password" name="password"><spring:errors delimiter="," path="password"></spring:errors><br /> 
<input type="submit">
</spring:form>
</body>
</html>

阅读更多
个人分类: JAVA
想对作者说点什么? 我来说一句

spring框架文档(英文版)

2016年01月19日 1.31MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭