Ezio's Blog
Posts Categories Tags Music Mood About
Ezio's Blog· Light
☰ Menu
Posts Categories Tags Music Mood About
Expand all Back to top Go to bottom

Spring Validation

Author: Ezio Date: October 19, 2022  11:09:28 Category: Spring

Spring Validation 是对 hibernate validation 的二次封装,用于支持spring mvc参数自动校验。

常用注解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Null                     // 限制只能为null
@NotNull // 限制必须不为null
@AssertFalse // 限制必须为false
@AssertTrue // 限制必须为true
@DecimalMax(value) // 限制必须为一个不大于指定值的数字
@DecimalMin(value) // 限制必须为一个不小于指定值的数字
@Digits(integer, fraction) // 限制必须为一个小数,且整数部分的位数不能超过integer,小数部分的位数不能超过fraction
@Future // 限制必须是一个将来的日期
@Max(value) // 限制必须为一个不大于指定值的数字
@Min(value) // 限制必须为一个不小于指定值的数字
@Past // 限制必须是一个过去的日期
@Pattern(value) // 限制必须符合指定的正则表达式
@Size(max, min) // 限制字符长度必须在min到max之间
@Past // 验证注解的元素值(日期类型)比当前时间早
@NotEmpty // 验证注解的元素值不为null且不为空(字符串长度不为0、集合大小不为0)
@NotBlank // 验证注解的元素值不为空(不为null、去除首位空格后长度为0),不同于@NotEmpty,@NotBlank只应用于字符串且在比较时会去除字符串的空格
@Email // 验证注解的元素值是Email,也可以通过正则表达式和flag指定自定义的email格式

Author: Ezio

Permalink: https://ezioy.cn/2022/10/19/Spring-Validation/

License: Copyright (c) 2019 CC-BY-NC-4.0 LICENSE

Slogan: Nothing is true,Everything is permitted

Tag(s): # Spring
back · home
Java-Shutdown Hook 缓存最终一致性以及业务解耦
Ezio © 2019 - 2026 | Powered by Hexo & Chic | 访客数量:   浏览次数: | 渝公网安备50011302222043 | 渝ICP备2023013933号-1