Hutool中那些常用的工具类和方法

本文详细介绍了Hutool库中的一些常用工具类,包括StrUtil、ClassPathResource、ReflectUtil、NumberUtil、BeanUtil、CollUtil、MapUtil、AnnotationUtil、SecureUtil、CaptchaUtil的使用方法,涵盖了字符串处理、资源读取、反射操作、数字运算、对象转换、集合操作、注解获取、加密解密和验证码生成等多个方面。
摘要由CSDN通过智能技术生成

//判断是否为空字符串
String str = “test”;
StrUtil.isEmpty(str);
StrUtil.isNotEmpty(str);
//去除字符串的前后缀
StrUtil.removeSuffix(“a.jpg”, “.jpg”);
StrUtil.removePrefix(“a.jpg”, “a.”);
//格式化字符串
String template = “这只是个占位符:{}”;
String str2 = StrUtil.format(template, “我是占位符”);
LOGGER.info("/strUtil format:{}", str2);

ClassPathResource

获取classPath下的文件,在Tomcat等容器下,classPath一般是WEB-INF/classes。

//获取定义在src/main/resources文件夹中的配置文件
ClassPathResource resource = new ClassPathResource(“generator.properties”);
Properties properties = new Properties();
properties.load(resource.getStream());
LOGGER.info("/classPath:{}", properties);

ReflectUtil

Java反射工具类,可用于反射获取类的方法及创建对象。

//获取某个类的所有方法
Method[] methods = ReflectUtil.getMethods(PmsBrand.class);
//获取某个类的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值