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");