一、

Starting with Spring 3.0, Spring supports the Java Validation API in Spring MVC . No extra configuration is required to make Java Validation work in Spring MVC . You just need to make sure an implementation of the Java API , such as Hibernate Validator, is in the project’s classpath.

1.

2.在实体类写约束

 public class Spitter {

   private Long id;

   @NotNull
@Size(min=5, max=16)
private String username; @NotNull
@Size(min=5, max=25)
private String password; @NotNull
@Size(min=2, max=30)
private String firstName; @NotNull
@Size(min=2, max=30)
private String lastName; @NotNull
@Email
private String email;

3.controller中

 @RequestMapping(value="/register", method=POST)
public String processRegistration(
@Valid Spitter spitter,
Errors errors) {
if (errors.hasErrors()) {
return "registerForm";
}

最新文章

  1. git使用
  2. Android自定义Dialog及其布局
  3. IOS基础之 (四) OC对象
  4. CS程序,服务器端弹出MessageBox.Show()之类的UI操作???禁止
  5. java中的线程创建和使用
  6. cocos2d-x 3.0正式版 环境搭建 (解决载入失败,未能载入XXX包)
  7. 制作Net程序的帮助文档--总结
  8. 折腾Python中的Tkinter
  9. MySQL索引创建、删除、查看
  10. 解决设置clickablespan后长按冲突的问题
  11. 移动端click事件300ms延迟
  12. ArcGIS 中UniqueValueRenderer和SimpleRenderer的异同点
  13. 微信小程序- 提示不在以下合法域名列表中
  14. sqlserver window身份验证时切换账户的快捷键
  15. Docker在Windows下的安装以及Hello World
  16. C# XML对象序列化、反序列化
  17. 十个jQuery图片画廊插件推荐
  18. 打开当前目录的其他exe
  19. Ubuntu14.04(64位)下gcc-linaro-arm-linux-gnueabihf交叉编译环境搭建
  20. Leader Election

热门文章

  1. Agile.Net 组件式开发平台 - 开发环境部署
  2. 反汇编windows htonl()函数
  3. Could not find artifact com.sun:tools:jar:1.5.0解决方法
  4. 从V$SQL_PLAN中FORMAT执行计划
  5. 第十二篇、HTML常用框架收集
  6. From MSI to WiX, Part 2 - ARP support, by Alex Shevchuk
  7. Qt-获取网络接口信息的综合示例
  8. Cloudcraft: 云架构图形可视化(智能AWS图表)
  9. PHP 类和继承
  10. NUnit单元测试