Well

huo dao lao xue dao lao


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

JAVA PROMOTE

发表于 2020-10-29

WORK-NOTE

发表于 2020-10-14

校验

判空:

工具类Tools,Tools.isEmpty(); Tools.isNotEmpty();。适用于对象判空。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public static boolean isEmpty(Object obj) {
if (obj == null) {
return true;
} else if (obj instanceof CharSequence) {
return ((CharSequence)obj).length() == 0;
} else if (obj instanceof Collection) {
return ((Collection)obj).isEmpty();
} else if (obj instanceof Map) {
return ((Map)obj).isEmpty();
} else if (!(obj instanceof Object[])) {
return false;
} else {
Object[] object = (Object[])((Object[])obj);
if (object.length == 0) {
return true;
} else {
boolean empty = true;

for(int i = 0; i < object.length; ++i) {
if (!isEmpty(object[i])) {
empty = false;
break;
}
}
return empty;
}
}
}

工具类CollectionUtils,CollectionUtils.isEmpty(); CollectionUtils.isNotEmpty();。适用于集合判空。

1
2
3
4
5
6
7
8
9
10
public static boolean isEmpty(Collection coll) {
return coll == null || coll.isEmpty();
}

// 低级示范
if(list != null && !list.isEmpty()){
// 这个里面取list中的值
}else{
// 做其他处理
}

工具类EmptyCheckUtil,EmptyCheckUtil.check(Object obj, boolean exclude, Sring... params); EmptyCheckUtil.checkAll();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public static void check(Object bean, boolean exclude, String... params) throws Exception {
if (bean == null) {
throw new ServiceException(DefaultResultStatus.PARAM_NOT_EMPTY);
} else {
Class type = bean.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
boolean needCheck = exclude;
for(int i = 0; i < propertyDescriptors.length; ++i) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean);
String[] var12 = params;
int var13 = params.length;
for(int var14 = 0; var14 < var13; ++var14) {
String param = var12[var14];
if (param.equals(propertyName)) {
needCheck = !exclude;
break;
}
}
if (needCheck && (result == null || "".equals(result))) {
throw new ServiceException(DefaultResultStatus.PARAM_NOT_EMPTY.getStatusCode(), propertyName + "不能为空!");
needCheck = exclude;
}
}
}

字符串判空,标准写法

1
2
3
4
String test = null;
if(result == null || "".equals(result)){
// true
}

注解

springboot注解

@Cacheable 缓存注解

RBAC-Project

发表于 2020-09-08 | 分类于 Project Learning

引言:

基于SpringBoot框架

阅读全文 »

SPC-Project

发表于 2020-06-29 | 分类于 Project Learning

引言:Spring Cloud学习

阅读全文 »

Git-Notes

发表于 2020-05-17 | 分类于 Tools

引言:

Git学习记录

阅读全文 »

Algorithm-Common

发表于 2020-05-09 | 分类于 Algorithm

引言:

常见题型

阅读全文 »

Blog-Notes

发表于 2020-05-07 | 分类于 Blog

引言

他山之石记录

阅读全文 »

JAVA-ReflectionAnnotation

发表于 2020-04-27 | 分类于 Interview Summary

引言:

Java 反射和注解学习笔记

阅读全文 »

JAVA-Spring

发表于 2020-04-24 | 分类于 Interview Summary

引言:

Java Spring框架笔记

阅读全文 »

JAVA-Web

发表于 2020-04-22 | 分类于 Interview Summary

引言:

Java Web学习笔记

阅读全文 »
123<i class="fa fa-angle-right"></i>
Mr.Zhang

Mr.Zhang

爱学习的小学生

30 日志
9 分类
26 标签
© 2020 Mr.Zhang
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4