1、导入maven坐标:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
2、StringUtils
//对String类型的字符串进行判空
String s = "今天天气正好";
StringUtils.isNotBlank(s);
StringUtils.isEmpty(s);
3.CollectionUtils
//对单列集合Collection判空
List array = new ArrayList();
CollectionUtils.isNotEmpty(array);
4.MapUtils
//在Map集合中根据key取value,内部都会做一个隐式判空
Map<String,Object> map = new HashMap();
map.put("str","字符串");
map.put("array",new ArrayList<>());
map.put("mapChild","new HashMap()");
String str = MapUtils.getString(map,"str");
List array = (List) MapUtils.getObject(map,"array");
Map mapChild = MapUtils.getMap(map,"mapChild");