在项目的pom.xml的dependencies中加入以下内容:
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
String str1=null;
System.out.println(StrUtil.isEmptyIfStr(str1));
System.out.println(StrUtil.isNotEmpty(str1));
String str2="abc";
System.out.println(StrUtil.isNumeric(str2));
String str3="123";
System.out.println(StrUtil.isNumeric(str3));
String str4=" 123\n";
System.out.println(StrUtil.cleanBlank(str4));
String str5="123456";
System.out.println(StrUtil.replace("123456", "123", "abc"));
String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
System.out.println(ReUtil.isMatch(ip,"192.168.1.1"));
List<String> list1= ListUtil.of("a","c","b");
System.out.println(list1);
List<String> list3=ListUtil.toList("a","b","c");
List<String> list4=ListUtil.sortByProperty(list3, "order");
System.out.println(list4);
List<String> list5=ListUtil.toList("a","b","c","c");
List<String> list6= CollectionUtil.distinct(list3);
System.out.println(list4);
String strDate = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
System.out.println(strDate); // 输出:2023-06-14 10:28:20
Date date = DateUtil.offsetDay(new Date(), -1); // 昨天的日期
System.out.println(date); // 输出:Mon Jun 13 10:28:20 CST 2023
boolean isSameDay = DateUtil.isSameDay(new Date(), DateUtil.parse("2023-06-14"));
System.out.println(isSameDay); // 输出:true
String md5Str = SecureUtil.md5("hutool");
System.out.println(md5Str); // 输出:a9d4bbde746b87e82f11c8dfb5cf1576
String sha1Str = SecureUtil.sha1("hutool");
System.out.println(sha1Str); // 输出:a5eeabe8bc7be3433fdec00a0f8dbf9b21b1b246
String result = HttpUtil.get("https://www.baidu.com");
System.out.println(result);
String postData = "username=admin&password=123456";
result = HttpUtil.post("http://localhost:8080/login", postData);
int randomInt = RandomUtil.randomInt(1, 100);
System.out.println(randomInt); // 输出:随机整数(1-100)
double randomDouble = RandomUtil.randomDouble(0, 1);
System.out.println(randomDouble); // 输出:随机浮点数(0-1)
String randomString = RandomUtil.randomString(10);
System.out.println(randomString); // 输出:随机字符串(长度为10)
boolean isNull = ObjectUtil.isNull(null);
System.out.println(isNull); // 输出:true
isNull = ObjectUtil.isNull(new Object());
System.out.println(isNull); // 输出:false
boolean isEqual = ObjectUtil.equal("hutool", "Hutool");
System.out.println(isEqual); // 输出:false
int intValue = Convert.toInt("123");
System.out.println(intValue); // 输出:123
String strValue = Convert.toStr(123);
System.out.println(strValue); // 输出:"123"
String dateStr = "2023-06-14";
Date date1 = Convert.toDate(dateStr);
System.out.println(date1); // 输出:Wed Jun 14 00:00:00 CST 2023
String dateStr2 = Convert.toStr(date, "yyyy-MM-dd");
System.out.println(dateStr2); // 输出:"2023-06-14"
boolean isEmail = Validator.isEmail("123@qq.com");
System.out.println(isEmail); // 输出:true
boolean isMobile = Validator.isMobile("13888888888");
System.out.println(isMobile); // 输出:true
boolean isCitizenId = Validator.isCitizenId("110101199003077777");
System.out.println(isCitizenId); // 输出:true
final Log log = LogFactory.get(); // 获取Logger对象
log.debug("debug message");
log.info("info message");
log.warn("warn message");
log.error("error message");
String jsonStr = "{\"name\":\"kaifamiao\",\"age\":18}";
JSONObject json = JSONUtil.parseObj(jsonStr);
System.out.println(json);
System.out.println(json.get("age"));
System.out.println(json.get("name")); // 输出:kaifamiao
JSONObject json2 = JSONUtil.createObj()
.put("name", "kaifamiao")
.put("age", 18);
String jsonStr2 = json2.toString();
System.out.println(jsonStr2); // 输出:{"age":18,"name":"kaifamiao"}
HttpResponse sp = HttpUtil.createPost("http://kaifamiao.dev").execute();
String body = sp.body();
System.out.println(body);
Map<String, Object> params = new HashMap<>();
params.put("name", "kaifamiao");
params.put("age", 18);
HttpResponse response = HttpUtil.createPost("https://kaifamiao.dev/").form(params).execute();
String body2 = response.body();
System.out.println(body2);
HttpUtil.downloadFile("https://example.com/image.png", FileUtil.file("image.png"));
powered by kaifamiao