Null
import org.apache.commons.collections4.CollectionUtils;
CollectionUtils.isNotEmpty(list);
!(list == null || list.isEmpty());
String字符串
// str = "2,5,8,7";
String str = "2,5,8,7";
List<Integer> idList = StringUtil.stringToList(str,",");
equals
Objects.equals(name, thisName);
String
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
String result = Joiner.on("-").join(list);
Map
实体转MAP
public static void Test() {
List<Student> list = new ArrayList<>();
list.add(new Student(1, "key1", "张"));
list.add(new Student(2, "key2", "李"));
Map<String, String> result = list.stream()
.collect(Collectors.toMap(student -> student.getKey(), Student::getName));
// result: {key1=zhangsan, key2=lisi}
}
Consumer
Consumer<String> consumer = (str) -> System.out.println(str);
consumer.accept("Hello Lambda!");
consumer.notify();
Function
Function<String, String> fun = (x) -> x + "/";
fun.apply("s");
DemoStringBuilder Optional
/**
* 获取 地图服务的名称 和 用户角色的名称
*
* @param sysMapAuthEntity
* @return serverName, roleName
*/
private String[] getServerNameAndRoleName(SysMapAuthEntity sysMapAuthEntity) {
MapServerEntity mapServerEntity = mapServerService
.getById(sysMapAuthEntity.getGisMapServerId());
StringBuilder sb = new StringBuilder();
Optional<MapServerEntity> serverOpt = Optional.ofNullable(mapServerEntity);
Consumer<String> slash = x -> sb.append(x + "/");
serverOpt.map(MapServerEntity::getSvcFolder).ifPresent(slash);
sb.append(mapServerEntity.getSvcName());
// _folder_serverName
String roleName = "_" + sb.toString().replace("/", "_");
//根据代码获取地图服务器
return new String[]{sb.toString(), roleName};
}
QueryWrapper
List<User> userList = this.userService.list(
new QueryWrapper<User>()
.lambda()
.ge(User::getAge, 18)
.likeLeft(User::getName, "ext")
.eq(User::getEmail, "ext@baomidou.com")
...
);