0
点赞
收藏
分享

微信扫一扫

Hutool 国产工具类库

IT程序员 2021-09-30 阅读 105
日记本

强大的国产工具类库

Java工具类库:Hutool      该工具类,只需要引入它的依赖

<dependency>   

        <groupId>cn.hutool</groupId>   

        <artifactId>hutool-all</artifactId>   

        <version>4.2.1</version>

</dependency>

一个官方提供的例子,模拟一下表单提交

public class Demo {   

        public static void main(String[] args) {      

             File file = new File("D:\\face.jpg");       

            // 第一种方式:自定义构建表单      

         HttpRequest request = HttpRequest                               .post("http://ip:port/xxxx")              

                 .form("file", file)               

                .form("fileType", "jpg");       

          HttpResponse response = request.execute();                                                  System.out.println(response.body());       

      // 第二种方式:使用统一表单,Http模块会自动识别参数类型,并完成上传           HashMap<String, Object> paramMap = new HashMap<>();               paramMap.put("author", "倪升武"); 

         paramMap.put("wechat", "程序员私房菜");      

         String result = HttpUtil.post("http://ip:port/xxxx", paramMap);               System.out.println(result);   }}

Hutool 还有其他很多工具,比如对文件、流、加密解密、转码、正则、线程、XML等JDK方法进行封装,组成各种Util工具类,HtmlUtil(HTML工具类)

    HtmlUtil.encode,可以将一些字符转化为安全字符,防止xss注入和SQL注入

    CronUtil(定时任务)使用 CronUtil 时,只需要在 src/main/resources/config 下放入 cron.setting 文件(默认是这个路径的这个文件),然后在文件中放入定时规则

参考 https://mp.weixin.qq.com/s/IQjsCXdhAbFTp7gr12iDWw

官网地址:https://www.hutool.cn/

举报

相关推荐

0 条评论