feat(utils): 添加自定义工具类

- 新增 Convert 类,提供类型转换方法
- 新增 JSONUtil 类,继承 JSON 工具类
- 新增 ObjectUtil 类,提供对象判断方法
- 新增 StrUtil 类,提供字符串常量
This commit is contained in:
cuijiawang
2025-02-14 18:09:37 +08:00
parent b21b8b1ea8
commit e58c672e6d
4 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package stu.utils;
/**
* @Author cuiJiaWang
* @Create 2025-02-10 14:19
*/
public class Convert extends cn.hutool.core.convert.Convert {
/*
toStr
toInt
*/
public static String toStr(Object value) {
return toStr(value, (String) null);
}
public static Integer toInt(Object value) {
return toInt(value, (Integer) null);
}
public static Integer toInt(Object value, Integer defaultValue) {
return (Integer) convertQuietly(Integer.class, value, defaultValue);
}
}

View File

@@ -0,0 +1,9 @@
package stu.utils;
/**
* @Author cuiJiaWang
* @Create 2025-02-10 14:45
*/
public class JSONUtil extends cn.hutool.json.JSONUtil {
}

View File

@@ -0,0 +1,18 @@
package stu.utils;
/**
* @Author cuiJiaWang
* @Create 2025-02-10 14:22
*/
public class ObjectUtil extends cn.hutool.core.util.ObjectUtil{
public static void main(String[] args) {
Object obj = null;
ObjectUtil.isNull(obj); // true
ObjectUtil.isEmpty(obj); // true
obj = "";
ObjectUtil.isEmpty(obj); // true
obj = " ";
System.out.println(ObjectUtil.isEmpty(obj));; // false
}
}

View File

@@ -0,0 +1,17 @@
package stu.utils;
/**
* @Author cuiJiaWang
* @Create 2025-02-10 14:10
*/
public class StrUtil extends cn.hutool.core.util.StrUtil {
// cn.hutool.core.util.StrUtil extends CharSequenceUtil implements StrPool
/*
StrPool":" ">" "{}" "\r" ...
*/
public static void main(String[] args) {
System.out.println(StrUtil.COLON); // :
}
}