Spring Boot中比较好用的工具

学无止境,气有浩然!

文章目录


前言

总结一下工作中用的比较好用的,Spring Boot中自带的一些工具类。后续会一直更新。


StringUtils

工作中用到的比较多的肯定是字符串的操作,有些jdk的无法满足,Spring Boot 进行拓展。

hasLength

主要判断的就是字符串不能是null且不是空串"",5.3之前版本是isEmpty方法,已经弃用。

java 复制代码
public static boolean hasLength(@Nullable String str) {
	return (str != null && !str.isEmpty());
}

hasText

这个用的比较多,是hasLength的加强版本,不是null,字符串长度不是0,并且至少包含一个非空白字符,在校验上游或者页面的时候非常有用。

java 复制代码
public static boolean hasText(@Nullable String str) {
	return (str != null && !str.isEmpty() && containsText(str));
}

trimWhitespace

作用其实跟Stringtrim()是一样的,但是好处是你可以不用判空。如果想要去除全部的空格,就是trimAllWhitespace,还有去除前边的空格trimLeadingWhitespace,去除末尾的空格trimTrailingWhitespace


startsWithIgnoreCase & endsWithIgnoreCase

就是判断是否以指定字符串开始或者结束,忽略大小写。

delete & deleteAny

删减字符串

uriDecode

可以帮你把url解码。


文件名操作

  • getFilename:获取文件名称
  • getFilenameExtension:获取拓展文件名

字符数组操作等等


BeanUtils

copyProperties

这个方法主要的好处就是,他的两个对象不必是同一个类,只要属性相同即可。


CollectionUtils

isEmpty

就是判断集合或者Mapnull,或者没有元素。

toArray & arrayToList

集合数组互转,个人感觉比jdk提供的好用。

未完待续

相关推荐
地瓜伯伯28 分钟前
SpringBoot项目整合Elasticsearch启动失败的常见错误总结
spring boot·elasticsearch·spring cloud
霸道流氓气质1 小时前
SpringBoot中集成LangChain4j+阿里百炼平台实现AI对话记忆功能、对话隔离、对话持久化到Redis功能
人工智能·spring boot·redis
人道领域3 小时前
【黑马点评日记02】Redis缓存优化:商户查询性能提升百倍
java·spring boot·spring·servlet·tomcat·intellij-idea
四斤年华3 小时前
关于SpringBoot在MultipartFile上java.nio.file.NoSuchFileException: /tmp/undertow
java·spring boot·nio
希望永不加班4 小时前
SpringBoot 中 AOP 实现接口限流
java·spring boot·后端·spring
Devin~Y4 小时前
互联网大厂Java面试:Spring Boot/Redis/Kafka/K8s 可观测 + RAG(向量检索/Agent)三轮追问实录
java·spring boot·redis·kafka·kubernetes·spring mvc·webflux
慕容卡卡4 小时前
SpringAI的那些事儿
java·人工智能·spring boot
tumeng07114 小时前
springboot与springcloud对应版本
java·spring boot·spring cloud
AI进阶客栈4 小时前
AI 幻觉与 RAG 技术详解:原理 + Spring Boot + pgvector 实战教程
人工智能·spring boot·后端
Java成神之路-4 小时前
SpringBoot 整合 SSM 全流程详解(含 JUnit+MyBatis 实战)(Spring系列18)
spring boot·junit·mybatis