hutool 工具类基本使用教程

2022-07-20,,

在之前没有接触到这个工具类的时候,感觉自己好像根本就不知道这个的存在,再次之前没有一个完善的知识体系,但是在发现这个工具类之后,才真的发现这个工具类是真的好用,下面我就简单的介绍一下关于这个工具类的使用,主要参考的是这几个博客

hutool 常用的一些方法简介:

简介

hutool是一个小而全的java工具类库,使java拥有函数式语言般的优雅,让java语言也可以“甜甜的”
这是hutool gitee上很亮眼的一句话,对于经常开发的老程序员来说,确实工具类的封装大大提高的开发效率,不说hutool 涉及到那些工具类的封装,想到哪里写到哪里吧~

对象转换为map

public static void test(){
        javaentity javaentity = new javaentity();
        javaentity.setname("张三");
        //  对象转换为map 输出结果 {name=张三, address=null}
        map map = beanutil.beantomap(javaentity);
        system.out.println(map);
    }

日期格式化类,提供常用的日期格式化对象

//-------------------------------------------------------------------------------------------------------------------------------- normal
    /** 标准日期格式:yyyy-mm-dd */
    public final static string norm_date_pattern = "yyyy-mm-dd";
    /** 标准日期格式 {@link fastdateformat}:yyyy-mm-dd */
    public final static fastdateformat norm_date_format = fastdateformat.getinstance(norm_date_pattern);
    
    /** 标准时间格式:hh:mm:ss */
    public final static string norm_time_pattern = "hh:mm:ss";
    /** 标准时间格式 {@link fastdateformat}:hh:mm:ss */
    public final static fastdateformat norm_time_format = fastdateformat.getinstance(norm_time_pattern);
 
    /** 标准日期时间格式,精确到分:yyyy-mm-dd hh:mm */
    public final static string norm_datetime_minute_pattern = "yyyy-mm-dd hh:mm";
    /** 标准日期时间格式,精确到分 {@link fastdateformat}:yyyy-mm-dd hh:mm */
    public final static fastdateformat norm_datetime_minute_format = fastdateformat.getinstance(norm_datetime_minute_pattern);
 
    /** 标准日期时间格式,精确到秒:yyyy-mm-dd hh:mm:ss */
    public final static string norm_datetime_pattern = "yyyy-mm-dd hh:mm:ss";
    /** 标准日期时间格式,精确到秒 {@link fastdateformat}:yyyy-mm-dd hh:mm:ss */
    public final static fastdateformat norm_datetime_format = fastdateformat.getinstance(norm_datetime_pattern);

md5加密

 string sign = secureutil.md5(append.tostring());
 system.out.println(sign);

http请求

  string result = httputil.post("https://fpdk.beijing.chinatax.gov.cn/nsbsqww/pltj.do", map);

list集合拆分

 list<list<string>> partitionlist = lists.partition(vallist, 30);

转换为int

  // 字符串转换为int类型
        system.out.println(convert.toint("3"));

数组转换为集合

string[] b = {"1", "2", "3", "4"};
system.out.println(convert.tolist(b));

字符串转为时间

  // 转换时间
 string date = "2020-05-06";
 system.out.println(convert.todate(date));

半角和全角转换

 // 半角转全角
string num = "123456";
system.out.println(convert.tosbc(num));
// 全角转半角
string num1 = "123456";
system.out.println(convert.todbc(num1));

unicode 和字符串转换

 //unicode 字符串转换
string con = "\\u5468\\u516d\\u8981\\u559d\\u9189";
system.out.println(convert.unicodetostr(con));
 
// 字符串转换为unicode
system.out.println(convert.strtounicode("hutool 挺好"));

时间单位转换

// 毫秒转换为分钟
 long a = 19299292;
 long minutes = convert.converttime(a, timeunit.milliseconds,timeunit.minutes);
 system.out.println(minutes);

金额大小写转换

 // 金额转换为人民币大写
 double a = 67556.32;
system.out.println(convert.digittochinese(a));

计时器

  timeinterval timer = dateutil.timer();
  // 执行过程
  converttest();
  system.out.println(timer.interval());

生成二维码

  // 生成二维码
        qrcodeutil.generate("https://hutool.cn/", 300, 300, fileutil.file("d:/qrcode.jpg"));

到此这篇关于hutool 工具类 基本使用详解的文章就介绍到这了,更多相关hutool 工具类 内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《hutool 工具类基本使用教程.doc》

下载本文的Word格式文档,以方便收藏与打印。