From 4477561d920a67ea244998bd1b47279c538613dc Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 20 Apr 2020 23:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/cm/common/utils/RegexUtil.java | 14 ++++++++++++++ .../cm/common/utils/annotation/AnnotationUtil.java | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java index a215211..4bbba71 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java @@ -43,6 +43,10 @@ public class RegexUtil { * 日期格式 */ private static final Pattern PATTERN_DATE = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*$"); + /** + * 时间戳格式 + */ + private static final Pattern PATTERN_DATETIME = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*(\\s+)([0-1][0-9]|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))*$"); /** * 身份证 */ @@ -142,6 +146,16 @@ public class RegexUtil { return PATTERN_DATE.matcher(input).matches(); } + /** + * 判断时间戳 + * + * @param input + * @return + */ + public static boolean isDatetime(String input) { + return PATTERN_DATETIME.matcher(input).matches(); + } + /** * 判断身份证 * diff --git a/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java b/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java index daa025d..6710fc5 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java @@ -161,6 +161,11 @@ public class AnnotationUtil { throw new ParamsException(String.format("%s格式非日期格式", name)); } return; + } else if (StringUtils.equals("datetime", verifyType)) { + if (!RegexUtil.isDatetime(value)) { + throw new ParamsException(String.format("%s格式非时间戳格式", name)); + } + return; } else if (StringUtils.equals("identity", verifyType)) { if (!RegexUtil.isIdentity(value)) { throw new ParamsException(String.format("%s格式非身份证格式", name));