工具类


引用: 作者:蜗牛2号 来源:CSDN 原文:https://blog.csdn.net/qq_35813653/article/details/89527729
版权声明:本文为博主原创文章,转载请附上博文链接!

一、项目地址:https://gitee.com/winallt/common-utils.git
二、项目结构:

三、功能描述:
3.1、加密功能
支持MD5,Base64和AES,具体方法如下

AESUtil {

/**
 * AES加密
 *
 * @param data
 * @return
 * @throws Exception
 */
public static String encryptData(String data,String  key) ;
/**
 * AES解密
 *
 * @param base64Data
 * @return
 * @throws Exception
 */
public static String decryptData(String base64Data,String  key) ;

}
Base64Util {

/**
 * 解密
 * @param encodedText
 * @return
 */
public static String decode(String encodedText);
/**
 * 加密
 * @param data
 * @return
 */
public static String encode(String  data) ;
/**
 * 解密(排除+ ,/这种在URL中必须转移的字符)
 * @param encodedText
 * @return
 */
public static String  decodeURL(String encodedText);
/**
 * 解密(排除+ ,/这种在URL中必须转移的字符)
 * @param data
 * @return
 */
public static String encodeURL(String  data) ;

}
MD5Util {

/**
 * 转换字节数组为16进制字串
 * @param b 字节数组
 * @return 16进制字串
 */
public static String byteArrayToHexString(byte[] b) ;
/**
 * 转换byte到16进制
 * @param b 要转换的byte
 * @return 16进制格式
 */
private static String byteToHexString(byte b) ;
/**
 * MD5编码
 * @param origin 原始字符串
 * @return 经过MD5加密之后的结果
 */
public static String MD5Encode(String origin);

}
3.2 代码生成功能
GenJavaObjectUtils {

/**
 *  根据word文档生成实体类(主要用于对接三方文档)
 * @param inputStream 输入的文件流
 * @param entity 实体类相关配置
 * @return
 * @throws IOException
 */
public static byte[] genEntity(InputStream inputStream, TableEntity entity) ;

/**
 * 根据json对象生成实体类
 * @param entity
 * @return
 * @throws IOException
 */
public static byte[] genEntity(JsonEntity entity);

}
3.3 日期对象处理
DateTimeUtils {

/**
 * 按照指定格式 格式化LocalDateTime
 *
 * @param localDateTime
 * @param formart       默认格式为yyyy-MM-dd HH:ss:mm
 * @return
 */
public static String formatLocalDateTime(@NotNull LocalDateTime localDateTime, @Nullable String formart) ;
/**
 * 按照指定格式 解析String
 *
 * @param dateTimeStr
 * @param formart     默认格式为yyyy-MM-dd HH:ss:mm
 * @return
 */
public static LocalDateTime parseLocalDateTime(@NotNull String dateTimeStr, @Nullable String formart);
/**
 * Date转LocalDateTime
 *
 * @param date
 * @param zoneId 时区
 * @return
 */
public static LocalDateTime dateToLocalDateTime(@NotNull Date date, @Nullable ZoneId zoneId);
/**
 * LocalDateTime转date
 *
 * @param localDateTime
 * @param zoneOffset    时区
 * @return
 */
public static Date localDateTimeToDate(LocalDateTime localDateTime, @Nullable ZoneOffset zoneOffset);
/**
 * 对日期时间更改
 *
 * @param localDateTime
 * @param amount
 * @param type
 * @param zoneOffset
 * @return
 */
public static LocalDateTime changeLocalDateTimeByType(LocalDateTime localDateTime, int amount, String type, @Nullable ZoneOffset zoneOffset) ;
/**
 * 根据时间获取时间戳
 *
 * @param dateTime
 * @return
 */
public static Long localDateTimeToTimestamp(LocalDateTime dateTime, @Nullable ZoneOffset zoneOffset) ;
/**
 * 根据时间戳获取日期时间
 *
 * @param timestamp
 * @return
 */
public static LocalDateTime timestampToLocalDateTime(@NotNull Long timestamp, @Nullable ZoneOffset zoneOffset) ;
/**
 *
 * @param date
 * @param type value:start or end
 * @param formart
 * @return
 */
public static LocalDateTime dateToDateTime(@NotNull String date, @NotNull String type, @Nullable String formart) ;

}
3.4 货币处理
CurrencyUtils {

/**
 * 元转分
 *
 * @param money 支持字符串,整型,浮点型,BigDecimal
 * @return
 */
public static BigDecimal yuanToFen(@NotNull Object money);
/**
 * 分转元
 *
 * @param money 支持字符串,整型,浮点型,BigDecimal
 * @return
 */
public static BigDecimal fenToYuan(@NotNull Object money);
/**
 * 转汉字
 *
 * @param money 精确到分
 * @return
 */
public static String toChinese(@NotNull BigDecimal money);

}
3.5 邮件发送
MailUtils {

/**
 * 不定人数发送邮件
 * @param title  主题
 * @param content 内容
 * @param address 地址
 * @throws Exception
 */
public static void send(String title, String content, String... address);

}
3.6 IP处理
IpUtils {

/**
 * 添加白名单(IP4:格式为xx.xx.xx.xx)
 */
public static void addWhiteIp(String whiteIp);
/**
 * 判断是否在白名单中(IP6:格式为xx.xx.xx.xx)
 *
 * @param ip
 * @return
 */
public static boolean isWhiteIp(String ip);
/**
 * 获得内网IP
 *
 * @return 内网IP
 */
private static String getIntranetIp() ;
/**
 * 获得外网IP(物理方法,可能获取虚拟机IP)
 *
 * @return 外网IP
 */
private static String getInternetIp() ;
/**
 * 获取真实公网IP(联网获取)
 *
 * @return
 */
public static String getRemoteIp();

}
3.7 反射增强
ReflectUtils {

/**
 * 获取对象的字段(不包括父类)
 *
 * @param t
 * @param access
 * @param <T>
 * @return
 */
public static <T> Field[] getFields(T t, boolean access);

/**
 * 获取对象全部属性,包括父类的
 * @param t
 * @param <T>
 * @return
 */
public static <T> Field[] getAllFields(T t);


/**
 * 获取父类泛型
 * @param bean
 * @return
 */
public static Class getSupperGenericInstance(Object bean) ;

}
3.8 对象COPY
ModelMapperUtils {

/**
 * 对象转对象
 * @param clazz
 * @param source
 * @param <T>
 * @param <D>
 * @return
 */
public static <T, D> T map(Class<T> clazz, final D source);
/**
 * 对象转集合
 * @param clazz
 * @param sources
 * @param <T>
 * @param <D>
 * @return
 */
public static <T, D> List<T> mapList(Class<T> clazz, final Collection<D> sources) ;
/**
 * 对象转Map(支持属性名和map的key值不一致)
 * @param bean
 * @param needNullParam
 * @return
 */
public static Map<String, Object> beanToMap(Object bean, boolean needNullParam) ;

}
3.9 word模版技术
WordUtils {

/**
 * 生成word文件
 *
 * @param templatePath 模板所在路径
 * @param templateName 模板名称
 * @param targetData  数据源
 */
public static byte[] createDoc(String templatePath, String templateName, Object targetData) ;


/**
 * 实现word模板填充
 *
 * @param inputStream
 *            模板输入流
 * @param bean
 *            待填充的数据
 * @throws IOException
 */
public static byte[] fillDocx(InputStream inputStream, Object bean) throws IOException ;



/**
 * 将word转换成html   支持 .doc and .docx
 * @param inputStream
 * @param type
 * @return
 * @throws TransformerException
 * @throws IOException
 * @throws ParserConfigurationException
 */
public static byte[] wordToHtml(InputStream inputStream,String type,String outPutFilePath)   ;

}
3.10 爬虫工具
WebMagicUtils {

/**
 * 抓取
 *
 * @param beginUrl 指定开始抓取的页面
 * @param linkReg  获取页面下满足要求的链接
 * @param xpath    指定抓取的内容
 * @return
 */
public Map<String, List<String>> getInfo(String beginUrl, String linkReg, Map<String, String> xpath,String proxyPath) ;

作者:蜗牛2号
来源:CSDN
原文:https://blog.csdn.net/qq_35813653/article/details/89527729
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值