🎨 补充工具类参考示例及注释,更新redame
This commit is contained in:
parent
851bd8a9db
commit
97260dcb6e
39
README.md
39
README.md
@ -12,18 +12,27 @@
|
||||
daysBetween 计算两个日期之间相差的天数
|
||||
overdueAdvent 计算临期/超期天数
|
||||
|
||||
### wx消息推送Mod
|
||||
wxMod
|
||||
### 消息推送类
|
||||
1 wxMod 微信公众号模板消息推送
|
||||
wxMod.WxRequestController 微信请求本服务接口 用于验证
|
||||
wxMod.WxSendMsgController 微信公众号发送消息(用于消息模板类的消息推送通知)
|
||||
前提:需要提前准备一个微信公众号,个人订阅号无效,可申请注册微信测试号
|
||||
前提:需要提前准备一个微信公众号,个人订阅号无效,可申请注册微信测试号
|
||||
|
||||
2 mail 邮件发送工具。由于依赖停止维护,请谨慎使用
|
||||
|
||||
### 邮件发送工具
|
||||
mail,由于依赖停止维护,请谨慎使用
|
||||
3 FeiShu 飞书模板消息推送webhook,需要建群邀请自定义机器人
|
||||
|
||||
### 加密工具
|
||||
utils.CryptoUtils
|
||||
字符串加密/解密 encryptAESPkcs7/decryptAESPkcs7
|
||||
1 utils.CryptoUtils (AES/CBC/PKCS7Padding 加解密)
|
||||
字符串加密/解密 encryptAESPkcs7/decryptAESPkcs7
|
||||
加解密文件参考Test.fileEncDecTest()
|
||||
|
||||
2 utils.SM2Util 国密2加解密方法 (工具类中有使用示例)
|
||||
generateKey 生成公私钥
|
||||
encrypt 加密
|
||||
decrypt 解密
|
||||
sign 签名
|
||||
verifySign 验签
|
||||
|
||||
### 文件工具
|
||||
utils.FileUtils
|
||||
@ -34,14 +43,16 @@
|
||||
Base64ToMultipartFile base64转MultipartFile
|
||||
|
||||
### 分页工具
|
||||
utils.page.*,详情查看Test.PageTest();
|
||||
utils.HandlePage 手动分页,可能有bug,待测试
|
||||
1 utils.page.*,详情查看Test.PageTest();
|
||||
2 utils.HandlePage 手动分页
|
||||
|
||||
### 回显方法
|
||||
utils.response.VoResult
|
||||
|
||||
### 根据实体类属性获取getAndSet方法
|
||||
utils.MethodGetAndSet 可能有bug,待测试
|
||||
utils.MethodGetAndSet 根据实体类属性名生成GET或SET方法
|
||||
getGetMethod 根据属性,获取get方法
|
||||
setValue 根据属性,拿到set方法,并把值set到对象中。参考Test.setObjectValueByField()。
|
||||
|
||||
### redis工具
|
||||
utils.redis.RedisCacheUtils
|
||||
@ -50,12 +61,14 @@
|
||||
utils.CamelCAsseUtil 将下划线分割字符串转为驼峰式 (aaa_bbb_ccc => aaaBbbCcc)
|
||||
|
||||
### 类型转换工具
|
||||
utils.EntityUtil 将实体类转为map <String, Object>
|
||||
utils.EntityUtil
|
||||
entityToMap 将实体类转为map <String, Object>
|
||||
getMultiValueMap 解析json字符串为MultiValueMap(传值为json字符串)
|
||||
|
||||
### 自动生成数据库所有实体类
|
||||
autoentity.pom.xml
|
||||
基于jOOQ的自动生成实体类功能,添加pom文件或者修改至自己的pom文件中,maven打包即可在对应处生成实体类
|
||||
需要在<build>内配置数据库信息 以及生成文件所在的位置信息
|
||||
基于jOOQ的自动生成实体类功能,添加pom文件或者修改至自己的pom文件中,maven打包即可在对应处生成实体类
|
||||
需要在<build>内配置数据库信息 以及生成文件所在的位置信息
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import lombok.Data;
|
||||
import mail.Mail;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -17,16 +18,11 @@ import java.util.List;
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
daysBetweenTest();
|
||||
overdueAdventTest();
|
||||
wxTest();
|
||||
mailTest();
|
||||
fileEncDecTest();
|
||||
fileDownTest();
|
||||
resultTest();
|
||||
setObjectValueByField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个日期之间相差的天数
|
||||
* DateTimeUtils.daysBetween 使用演示
|
||||
*/
|
||||
public static void daysBetweenTest() throws Exception {
|
||||
@ -37,6 +33,7 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算临期/超期天数
|
||||
* DateTimeUtils.overdueAdvent 使用演示
|
||||
*/
|
||||
public static void overdueAdventTest() throws Exception {
|
||||
@ -49,6 +46,7 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送公众号模板消息
|
||||
* wxMod 使用演示
|
||||
*/
|
||||
public static void wxTest(){
|
||||
@ -56,6 +54,7 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件发送
|
||||
* mail 使用演示
|
||||
*/
|
||||
public static void mailTest() throws Exception {
|
||||
@ -63,6 +62,7 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* AES/CBC/PKCS7Padding 加解密
|
||||
* CryptoUtils 使用演示 文件加密/解密
|
||||
*/
|
||||
public static void fileEncDecTest() throws Exception{
|
||||
@ -87,7 +87,8 @@ public class Test {
|
||||
}
|
||||
|
||||
/**
|
||||
* FileUtils.getFile 使用演示 获取网络文件并下载
|
||||
* 获取网络文件并下载
|
||||
* FileUtils.getFile 使用演示
|
||||
*/
|
||||
public static void fileDownTest() throws Exception{
|
||||
File file = FileUtils.getFile("https://www.baidu.com/a.jpg");
|
||||
@ -123,4 +124,21 @@ public class Test {
|
||||
//return VoResult.success().add("key","value");
|
||||
//return VoResult.errorParam("报错啦!!!");
|
||||
}
|
||||
|
||||
/**
|
||||
*根据属性,拿到set方法,并把值set到对象中
|
||||
*/
|
||||
public static void setObjectValueByField() throws NoSuchFieldException {
|
||||
|
||||
String field = "name";
|
||||
String value = "李雷";
|
||||
User user = new User();
|
||||
MethodGetAndSet.setValue(user,user.getClass(),field,User.class.getDeclaredField(field).getType(),value);
|
||||
System.out.println(user);
|
||||
}
|
||||
@Data
|
||||
public static class User{
|
||||
private String name;
|
||||
private String age;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ public class Mail {
|
||||
* @param toMail 收件地址
|
||||
* @param strTitle 标题
|
||||
* @param strContent 内容
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void sendMail(String mailName,String mailPwd,String toMail,String strTitle,String strContent) throws Exception{
|
||||
|
||||
|
@ -15,8 +15,8 @@ public class DateTimeUtils {
|
||||
|
||||
/**
|
||||
* 计算两个日期之间相差的天数
|
||||
* @param smdate
|
||||
* @param bdate
|
||||
* @param smdate 开始时间
|
||||
* @param bdate 结束时间
|
||||
*/
|
||||
public static int daysBetween(Date smdate, Date bdate) throws ParseException {
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
@ -9,10 +9,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @author fuhouyin
|
||||
* @time 2023/2/1 11:55
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
/**
|
||||
|
@ -2,11 +2,6 @@ package utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fuhouyin
|
||||
* @time 2023/2/1 15:07
|
||||
* 手动分页,待测试
|
||||
*/
|
||||
public class HandlePage {
|
||||
|
||||
/**分页 start = (page - 1) * size, end = page * size*/
|
||||
|
@ -3,15 +3,10 @@ package utils;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author fuhouyin
|
||||
* @time 2023/2/1 15:10
|
||||
* 根据实体类属性获取getAndSet方法
|
||||
*/
|
||||
public class MethodGetAndSet {
|
||||
|
||||
/**根据属性,获取get方法*/
|
||||
private Object getGetMethod(Object ob , String name)throws Exception{
|
||||
public static Object getGetMethod(Object ob , String name)throws Exception{
|
||||
Method[] m = ob.getClass().getMethods();
|
||||
for(int i = 0;i < m.length;i++){
|
||||
if(("get"+name).toLowerCase().equals(m[i].getName().toLowerCase())){
|
||||
@ -22,7 +17,7 @@ public class MethodGetAndSet {
|
||||
}
|
||||
|
||||
/**根据属性,拿到set方法,并把值set到对象中*/
|
||||
private void setValue(Object obj,Class<?> clazz,String filedName,Class<?> typeClass,Object value){
|
||||
public static void setValue(Object obj, Class<?> clazz, String filedName, Class<?> typeClass, Object value){
|
||||
filedName = removeLine(filedName);
|
||||
String methodName = "set" + filedName.substring(0,1).toUpperCase()+filedName.substring(1);
|
||||
try{
|
||||
@ -34,7 +29,7 @@ public class MethodGetAndSet {
|
||||
}
|
||||
|
||||
/**通过class类型获取获取对应类型的值*/
|
||||
private Object getClassTypeValue(Class<?> typeClass, Object value){
|
||||
public static Object getClassTypeValue(Class<?> typeClass, Object value){
|
||||
if(typeClass == int.class || value instanceof Integer){
|
||||
if(null == value){
|
||||
return 0;
|
||||
@ -81,7 +76,7 @@ public class MethodGetAndSet {
|
||||
}
|
||||
|
||||
/**处理字符串 如: abc_dex ---> abcDex*/
|
||||
private String removeLine(String str){
|
||||
public static String removeLine(String str){
|
||||
if(null != str && str.contains("_")){
|
||||
int i = str.indexOf("_");
|
||||
char ch = str.charAt(i+1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user