In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use Hutool for you. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Hutool is a Java toolkit and just a toolkit that helps us simplify every line of code, reduce every method, and make the Java language "sweet". Hutool was originally a collation of the "util" package in my project, then gradually accumulated and added more non-business-related functions, and extensively learned the essence of other open source projects, and finally formed a rich open source toolset after self-collation and modification. (copied from the author's brief introduction)
Function
A Java basic utility class that encapsulates JDK methods such as file, stream, encryption and decryption, transcoding, regularization, threading, XML, etc., to form various Util utility classes, and provides the following components:
Hutool-aop JDK dynamic proxy encapsulation, providing section support under non-IOC
Hutool-bloomFilter Bloom filtering, which provides some Hash algorithm Bloom filtering
Hutool-cache caching
Hutool-core core, including Bean operations, dates, various Util, etc.
Hutool-cron timing task module, which provides timing tasks for Crontab-like expressions
Hutool-crypto encryption and decryption module
Data operation after hutool-db JDBC encapsulation, based on ActiveRecord idea
Hutool-dfa Multi-keyword search based on DFA Model
Hutool-extra extension module, encapsulation for third parties (template engine, mail, etc.)
Http client Encapsulation of hutool-http based on HttpUrlConnection
Hutool-log automatically identifies the log facade implemented by the log
Hutool-script script execution wrapper, such as Javascript
Hutool-setting more powerful Setting configuration files and Properties encapsulation
Hutool-system system parameter call encapsulation (JVM information, etc.)
Hutool-json JSON implementation
Implementation of hutool-captcha Picture CAPTCHA
Simple test
These two days to use Hutool to replace some of the code in Halo, I have to say, it is very smooth to use, the following is a brief introduction to some of the Hutool tool classes I used.
SecureUtil (encryption and decryption tool)
It is mainly used when logging in and when changing the password, because the password in the database is encrypted by md5, so you need to encrypt it first and then query the database when you log in. If you use Hutool, you only need to call the md5 method in SecureUtil.
User = userService.userLoginByName (loginName,SecureUtil.md5 (loginPwd))
HtmlUtil (HTML utility class)
This utility class is more powerful, but the one I use most in Halo is HtmlUtil.encode, which can convert some characters to safe characters to prevent xss injection and SQL injection, such as the following comment submission.
Comment.setCommentAuthor (HtmlUtil.encode (comment.getCommentAuthor ()
This is to prevent a little villain from deliberately writing some executable js code and then submitting comments, which will be executed in the background panel, which is dangerous. You can use the encode method to convert the tag to, so that the js code will not be executed.
In addition, HtmlUtil also provides the following methods, which you can try if you are interested.
HtmlUtil.restoreEscaped restores escaped HTML special characters
HTML characters in HtmlUtil.encode escaped text are safe characters
HtmlUtil.cleanHtmlTag clears all HTML tags
HtmlUtil.removeHtmlTag clears the specified HTML tags and content surrounded by tags
HtmlUtil.unwrapHtmlTag clears the specified HTML tag, excluding content
HtmlUtil.removeHtmlAttr removes attributes from HTML tags
HtmlUtil.removeAllHtmlAttr removes all attributes from the specified tag
HtmlUtil.filter filters HTML text to prevent XSS attacks
CronUtil (scheduled tasks)
This tool is even more powerful, it doesn't need a framework like quartz to do timing tasks, and CronUtil doesn't need any other dependencies, just build a configuration file under resources, and then start scheduled tasks when the program starts, such as Halo's scheduled backup function (backed up at 1: 00 a. M. every day).
Cron.setting:
Cc.ryanc.halo.web.controller.admin.BackupController.backupResources = 0 01 * *? cc.ryanc.halo.web.controller.admin.BackupController.backupDatabase = 0 01 * *? cc.ryanc.halo.web.controller.admin.BackupController.backupPosts = 0 01 * *? @ Overridepublic void onApplicationEvent (ContextRefreshedEvent event) {this.loadActiveTheme (); this.loadOptions (); this.loadFiles (); this.loadThemes (); / / start scheduled task CronUtil.start () Log.info ("scheduled task started successfully!") This is the end of the article on "how to use Hutool". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.