diff --git a/README.adoc b/README.adoc index 05cbeee..5d304a5 100644 --- a/README.adoc +++ b/README.adoc @@ -5,19 +5,21 @@ image:https://api.codacy.com/project/badge/Grade/f2fc8d2aa9594a0bae6e2a445caa56d image:https://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2",link="https://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://maven-badges.herokuapp.com/maven-central/com.ecfront.dew/common/badge.svg["Maven Central",link="https://maven-badges.herokuapp.com/maven-central/com.ecfront.dew/common/"] +Dew Common的理念是简化Java开发中最常用的操作,同时尽可能少地引入第三方包,做到通用、易用、精简。 + === 功能 -. Json与Java对象互转 -. Java Bean操作 -. Java Class扫描操作 -. Shell脚本操作 -. 加解密操作 -. 通用拦截器栈 -. 定时器操作 -. 常用文件操作 -. 常用字段操作 -. 常用时间处理 -. 主流文件MIME整理 +. Json与Java对象互转,支持泛型 +. Java Bean操作,Bean复制、反射获取/设置注解、字段、方法等 +. Java Class扫描操作,根据注解或名称过滤 +. Shell脚本操作,Shell内容获取、成功捕获及进度报告等 +. 加解密操作,Base64、MD5/BCrypt/SHA等对称算法和RSA等非对称算法 +. 通用拦截器栈,前/后置、错误处理等 +. 定时器操作,定时和周期性任务 +. 常用文件操作,根据不同情况获取文件内容 +. 常用字段操作,各类字段验证及身份证提取 +. 常用时间处理,常规时间格式化模板 +. 主流文件MIME整理,MIME分类 . 响应处理及分页模型 === 使用 @@ -29,37 +31,37 @@ NOTE: 文档地址: http://gudaoxuri.github.io/dew-common/[http://gudaoxuri.gi com.ecfront.dew common - 1.1.1 + 1.2.0 ---- -==== Json与Java对象互转(DEW.json) +==== Json与Java对象互转($.json) [source,java] ---- // 将Json字符串转成JsonNode -JsonNode json = DEW.json.toJson("{'name':'gudaoxuri'}"); +JsonNode json = $.json.toJson("{'name':'gudaoxuri'}"); // 获取json中的值 String name = json.get("name").asText(); // 将Json转成Java对象 -JavaModel java = DEW.json.toObject(json,JavaModel.class); +JavaModel java = $.json.toObject(json,JavaModel.class); // 将Json字符串转成Java对象 -java = DEW.json.toObject("{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}", JavaModel.class); +java = $.json.toObject("{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}", JavaModel.class); // 将Json字符串转成List对象 -List javas = DEW.json.toList("[{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}]", JavaModel.class); +List javas = $.json.toList("[{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}]", JavaModel.class); // 将Java对象转成JsonNode -json = DEW.json.toJson(java); +json = $.json.toJson(java); // 将List对象转成JsonNode -json = DEW.json.toJson(javas); +json = $.json.toJson(javas); // 将JsonNode转成Json字符串 -String str = DEW.json.toJsonString(json); +String str = $.json.toJsonString(json); // 将Java对象转成Json字符串 -str = DEW.json.toJsonString(java); +str = $.json.toJsonString(java); // 将List对象转成Json字符串 -str = DEW.json.toJsonString(javas); +str = $.json.toJsonString(javas); static class JavaModel{ private String name; @@ -71,7 +73,7 @@ static class JavaModel{ TIP: 更多示例见`JsonHelperTest.java` -==== Java Bean操作(DEW.bean) +==== Java Bean操作($.bean) [source,java] ---- @@ -79,46 +81,46 @@ TIP: 更多示例见`JsonHelperTest.java` User ori = new User(); ori.setName("gudaoxuri"); User dist = new User(); -DEW.bean.copyProperties(ori, dist); +$.bean.copyProperties(ori, dist); // 获取Class的注解信息(此处为IdxController类的RPC注解) -TestAnnotation.RPC rpc = DEW.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class); +TestAnnotation.RPC rpc = $.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class); // 获取Class的字段信息(此处为IdxController类) -Map fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, null, null); +Map fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, null); // 获取Class的方法信息(此处为IdxController类) -List methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, null, null); +List<$.bean.MethodInfo> methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, null); // 获取字段对应的Get/Set方法(此处为User类) -Map rel = DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null); +Map rel = $.bean.parseRelFieldAndMethod(User.class, null, null, null, null); User user = new User(); user.setName("gudaoxuri"); // 根据字段的Get方法获取对应的值 -Map values = DEW.bean.findValuesByRel(user, DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null)); +Map values = $.bean.findValuesByRel(user, $.bean.parseRelFieldAndMethod(User.class, null, null, null, null)); // 获取对象所有字段的值 -values = DEW.bean.findValues(user, null, null, null, null); +values = $.bean.findValues(user, null, null, null, null); // 根据字段名称获取对应的值(需要有标准的Get方法) -Object value = DEW.bean.getValue(user, "name"); +Object value = $.bean.getValue(user, "name"); // 根据字段名称设置值(需要有标准的Set方法) -DEW.bean.setValue(user, "name", "gudaoxuri"); +$.bean.setValue(user, "name", "gudaoxuri"); ---- TIP: 更多示例见`BeanHelperTest.java` -==== Java Class扫描操作(DEW.clazz) +==== Java Class扫描操作($.clazz) [source,java] ---- // 扫描获取指定包下符合条件的class类(此处要求包含Deprecated注解) -Set> resultInFile = DEW.clazz.scan("com.ecfront.dew.common.test", new HashSet>(){{add(Deprecated.class);}},null); +Set> resultInFile = $.clazz.scan("com.ecfront.$.common.test", new HashSet>(){{add(Deprecated.class);}},null); // 扫描获取指定包下符合条件的class类(此处要求包含Before\\w*类名) -Set> resultInJar = DEW.clazz.scan("org.junit",null, new HashSet(){{add("Before\\w*");}}); +Set> resultInJar = $.clazz.scan("org.junit",null, new HashSet(){{add("Before\\w*");}}); ---- TIP: 更多示例见`ClassScanHelperTest.java` -==== Shell脚本操作(DEW.shell()) +==== Shell脚本操作($.shell()) [source,java] ---- -DEW.shell().execute( +$.shell().execute( "/opt/test.sh", // sh文件路径,包含参数 "test1", // 任务ID "done!", // 成功标识,只要捕捉到此标识就视为成功,为null时不会调用ReportHandler的success方法,执行结束后会调用ReportHandler的fail方法 @@ -146,70 +148,70 @@ DEW.shell().execute( TIP: 更多示例见`ShellProcessorTest.java` -==== 加解密操作(DEW.encrypt) +==== 加解密操作($.encrypt) [source,java] ---- // 字符串 转 Base64 -String base64 = DEW.encrypt.encodeStringToBase64("gudaoxuri", "UTF-8"); +String base64 = $.encrypt.encodeStringToBase64("gudaoxuri", "UTF-8"); // 数组 转 Base64 -base64 = DEW.encrypt.encodeBytesToBase64("gudaoxuri".getBytes(), "UTF-8"); +base64 = $.encrypt.encodeBytesToBase64("gudaoxuri".getBytes(), "UTF-8"); // Base64 转 字符串 -String str = DEW.encrypt.decodeBase64ToString(base64, "UTF-8"); +String str = $.encrypt.decodeBase64ToString(base64, "UTF-8"); // Base64 转 字符串 -byte[] bytes = DEW.encrypt.decodeBase64ToBytes(base64); +byte[] bytes = $.encrypt.decodeBase64ToBytes(base64); // 对称加密(此处使用SHA-256算法,支持如bcrypt SHA-256 MD5等算法) -String encrypt = DEW.encrypt.Symmetric.encrypt("gudaoxuri", "SHA-256"); +String encrypt = $.encrypt.Symmetric.encrypt("gudaoxuri", "SHA-256"); // 对称加密 - 验证(对于bcrypt之类默认使用随机slat的加密算法必须使用此方法验证) -DEW.encrypt.Symmetric.validate("gudaoxuri", encrypt, "SHA-256"); +$.encrypt.Symmetric.validate("gudaoxuri", encrypt, "SHA-256"); // 非对称加密 - 生成公钥和私钥 -Map keys = DEW.encrypt.Asymmetric.generateKeys("RSA", 1024, "UTF-8"); +Map keys = $.encrypt.Asymmetric.generateKeys("RSA", 1024, "UTF-8"); String publicStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC47dAhLLB3xhDWccgEheqTbRimAhluN/ixNyYU/MvExN/bwytthiWViRV2H1sGrGr5JyH3qQSFa57jInbXD6lGN24aw2TfiejLWGkj0hMEXEtj4Bf9OuQhHUmy8unLygOuBlIhtfPLp9cSLBgVVHbt33buNTkL7fvdE2U9B3JVyQIDAQAB"; // 非对称加密 - 获取公钥文件 -PublicKey publicKey = DEW.encrypt.Asymmetric.getPublicKey(publicStr, "RSA"); +PublicKey publicKey = $.encrypt.Asymmetric.getPublicKey(publicStr, "RSA"); String privateStr = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALjt0CEssHfGENZxyASF6pNtGKYCGW43+LE3JhT8y8TE39vDK22GJZWJFXYfWwasavknIfepBIVrnuMidtcPqUY3bhrDZN+J6MtYaSPSEwRcS2PgF/065CEdSbLy6cvKA64GUiG188un1xIsGBVUdu3fdu41OQvt+90TZT0HclXJAgMBAAECgYEAjXFndVhHCPU3P637PGppBqW06pREeybYUkNKH1dTS4cBaYcXmke2S290OMq2xp3tm++wbUqbKKkt97AOkWNrJfq8Ecpdw9s3c7yQGWaPuwiX38Cgtq6r0utjT20YgR6etGpqafoBt93RZpEm0eEzFPUnS7qYc86HprL0RJ0/i7kCQQDaOmvO82cYIK1ESkA0GdDVQoz2A1V8HvEWOsccRGqlWuasLUccyBnx1G/LDZUxcPOraDyxI8sdl7VbweLR0H9LAkEA2O/rWXwnSYKqdpt+OhpUBHNnMs3IMvRzefJ1zObnIMyYR3KXtpQ/fL4gEquNwJgFIaPJVg5/3zHISEw3e8XOuwJAIDrGl07tZ+vTiyVoLAmwBP8KMH83jdhIBN9zbqJQGdG+Bam+Oer3ofac+CEuapni8uq3I/ZEVj+EomOVKyWe1wJAATztROd2ee7q9h5RDBfWXughsKKH//JxLkL59R9kNkW0oMPApeQWsKmNGU4tUuoLLXP31CvlAusPz4nPzz8DvQJBAJXpICPNJw84fONzS0raRqlFoZMMI0cqeGtPIiCHKaRHyzQv/FFu2KxUcCrod8PngaBFRselzrwZILmXHqrHc1M="; // 非对称加密 - 获取私钥文件 -PrivateKey privateKey = DEW.encrypt.Asymmetric.getPrivateKey(privateStr, "RSA"); +PrivateKey privateKey = $.encrypt.Asymmetric.getPrivateKey(privateStr, "RSA"); String d = "Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。"; // 非对称加密 - 公钥加密/私钥解密 -byte[] encryptByPub = DEW.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA"); -String result = new String(DEW.encrypt.Asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8"); +byte[] encryptByPub = $.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA"); +String result = new String($.encrypt.Asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8"); // 非对称加密 - 私钥加密/公钥解密 -byte[] encryptByPriv = DEW.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA"); -byte[] decryptByPub = DEW.encrypt.Asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA"); -DEW.encrypt.Asymmetric.verify(publicKey, decryptByPub, - DEW.encrypt.Asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), +byte[] encryptByPriv = $.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA"); +byte[] decryptByPub = $.encrypt.Asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA"); +$.encrypt.Asymmetric.verify(publicKey, decryptByPub, + $.encrypt.Asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA"); ---- TIP: 更多示例见`EncryptHelperTest.java` -==== 通用拦截器栈(DEW.interceptor) +==== 通用拦截器栈($.interceptor) [source,java] ---- // 没有注册拦截器的情况 -Resp> resp = DEW.interceptor.process("none", new Obj("1"), new HashMap<>(), (obj, context) -> +Resp> resp = $.interceptor.process("none", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(resp.ok()); Assert.assertEquals("1", resp.getBody().getObj().getF()); // 注册了一个拦截器A -DEW.interceptor.register("test", new InterceptorA()); -resp = DEW.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> +$.interceptor.register("test", new InterceptorA()); +resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(resp.ok()); Assert.assertEquals("3", resp.getBody().getObj().getF()); // 注册了另一个拦截器B,假设B执行会报错 -DEW.interceptor.register("test", new InterceptorB()); -resp = DEW.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> +$.interceptor.register("test", new InterceptorB()); +resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(!resp.ok()); @@ -267,56 +269,56 @@ public class InterceptorB implements DewInterceptor { TIP: 更多示例见`InterceptorTest.java` -==== 定时器操作(DEW.timer) +==== 定时器操作($.timer) [source,java] ---- // 延迟任务 -DEW.timer.timer(1, () -> // Do Something); +$.timer.timer(1, () -> // Do Something); // 周期性任务,参数 fixedRate 为true时表示每periodSec执行,为false表示fixedDelay,表示在当前任务执行完成后过periodSec再执行 -String taskId = DEW.timer.periodic(1, true, () -> // Do Something); +String taskId = $.timer.periodic(1, true, () -> // Do Something); // 取消周期性任务 -DEW.timer.cancel(taskId); +$.timer.cancel(taskId); ---- TIP: 更多示例见`TimerHelperTest.java` -==== 常用文件操作(DEW.file) +==== 常用文件操作($.file) [source,java] ---- // 根据classpath读取文件所有内容(jar包外路径优先),另外readAllByPath、readAllByFile、readAllByPathName等衍生方法 -String conf=DEW.file.readAllByClassPath("conf1.json","UTF-8"); +String conf=$.file.readAllByClassPath("conf1.json","UTF-8"); ---- TIP: 更多示例见`FileHelperTest.java` -==== 常用字段操作(DEW.field) +==== 常用字段操作($.field) [source,java] ---- // 验证邮箱格式是否合法 -DEW.field.validateEmail("i@sunisle.org"); +$.field.validateEmail("i@sunisle.org"); // 验证手机号格式是否合法 -DEW.field.validateMobile("18657120000"); +$.field.validateMobile("18657120000"); // 是否是汉字 -DEW.field.isChinese("孤岛旭日"); +$.field.isChinese("孤岛旭日"); // 验证身份证是否合法 -DEW.field.validateIdNumber("330102199901015759"); +$.field.validateIdNumber("330102199901015759"); // 根据身份编号获取年龄 -DEW.field.getAgeByIdCard("330102199901015759"); +$.field.getAgeByIdCard("330102199901015759"); // 根据身份编号获取生日 -DEW.field.getBirthByIdCard("330102199901015759"); +$.field.getBirthByIdCard("330102199901015759"); // 根据身份编号获取生日年 -DEW.field.getYearByIdCard("330102199901015759"); +$.field.getYearByIdCard("330102199901015759"); // 根据身份编号获取生日月 -DEW.field.getMonthByIdCard("330102199901015759"); +$.field.getMonthByIdCard("330102199901015759"); // 根据身份编号获取生日天 -DEW.field.getDateByIdCard("330102199901015759"); +$.field.getDateByIdCard("330102199901015759"); // 根据身份编号获取性别 -DEW.field.getGenderByIdCard("330102199901015759"); +$.field.getGenderByIdCard("330102199901015759"); // 根据身份编号获取户籍省份 -DEW.field.getProvinceByIdCard("330102199901015759"); +$.field.getProvinceByIdCard("330102199901015759"); ---- TIP: 更多示例见`FieldHelperTest.java` diff --git a/docs/index.html b/docs/index.html index 9bc72e5..8e87b74 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,11 +1,10 @@ - + - + - Dew Common — Java常用操作工具集 - +
-

1. Dew Common — Java常用操作工具集

+

Dew Common — Java常用操作工具集

@@ -467,51 +435,54 @@

1 Apache License 2 Maven Central

+
+

Dew Common的理念是简化Java开发中最常用的操作,同时尽可能少地引入第三方包,做到通用、易用、精简。

+
-

1.1. 功能

+

功能

  1. -

    Json与Java对象互转(JsonHelper)

    +

    Json与Java对象互转,支持泛型

  2. -

    Java Bean操作(BeanHelper)

    +

    Java Bean操作,Bean复制、反射获取/设置注解、字段、方法等

  3. -

    Java Class扫描操作(ClassScanHelper)

    +

    Java Class扫描操作,根据注解或名称过滤

  4. -

    Shell脚本操作(ShellProcessor)

    +

    Shell脚本操作,Shell内容获取、成功捕获及进度报告等

  5. -

    加解密操作(EncryptHelper)

    +

    加解密操作,Base64、MD5/BCrypt/SHA等对称算法和RSA等非对称算法

  6. -

    通用拦截器栈(DewInterceptorProcessor)

    +

    通用拦截器栈,前/后置、错误处理等

  7. -

    定时器操作(TimerHelper)

    +

    定时器操作,定时和周期性任务

  8. -

    常用文件操作(FileHelper)

    +

    常用文件操作,根据不同情况获取文件内容

  9. -

    常用字段操作(FieldHelper)

    +

    常用字段操作,各类字段验证及身份证提取

  10. -

    常用时间处理(TimeHelper)

    +

    常用时间处理,常规时间格式化模板

  11. -

    主流文件MIME整理(MimeHelper)

    +

    主流文件MIME整理,MIME分类

  12. -

    响应处理及分页模型(Resp & PageDTO)

    +

    响应处理及分页模型

-

1.2. 使用

+

使用

@@ -529,37 +500,37 @@

1.2. 使用

<parent>
         <groupId>com.ecfront.dew</groupId>
         <artifactId>common</artifactId>
-        <version>1.1.1</version>
+        <version>1.2.0</version>
 </parent>
-

1.2.1. Json与Java对象互转(JsonHelper)

+

Json与Java对象互转($.json)

// 将Json字符串转成JsonNode
-JsonNode json = JsonHelper.toJson("{'name':'gudaoxuri'}");
+JsonNode json = $.json.toJson("{'name':'gudaoxuri'}");
 // 获取json中的值
 String name = json.get("name").asText();
 
 // 将Json转成Java对象
-JavaModel java = JsonHelper.toObject(json,JavaModel.class);
+JavaModel java = $.json.toObject(json,JavaModel.class);
 // 将Json字符串转成Java对象
-java = JsonHelper.toObject("{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}", JavaModel.class);
+java = $.json.toObject("{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}", JavaModel.class);
 // 将Json字符串转成List对象
-List<JavaModel> javas = JsonHelper.toList("[{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}]", JavaModel.class);
+List<JavaModel> javas = $.json.toList("[{'name':'gudaoxuri','date':'2016-07-12 12:00:00'}]", JavaModel.class);
 
 // 将Java对象转成JsonNode
-json = JsonHelper.toJson(java);
+json = $.json.toJson(java);
 // 将List对象转成JsonNode
-json = JsonHelper.toJson(javas);
+json = $.json.toJson(javas);
 
 // 将JsonNode转成Json字符串
-String str = JsonHelper.toJsonString(json);
+String str = $.json.toJsonString(json);
 // 将Java对象转成Json字符串
-str = JsonHelper.toJsonString(java);
+str = $.json.toJsonString(java);
 // 将List对象转成Json字符串
-str = JsonHelper.toJsonString(javas);
+str = $.json.toJsonString(javas);
 
 static class JavaModel{
     private String name;
@@ -583,32 +554,32 @@ 

-

1.2.2. Java Bean操作(BeanHelper)

+

Java Bean操作($.bean)

// Bean Copy
 User ori = new User();
 ori.setName("gudaoxuri");
 User dist = new User();
-BeanHelper.copyProperties(ori, dist);
+$.bean.copyProperties(ori, dist);
 // 获取Class的注解信息(此处为IdxController类的RPC注解)
-TestAnnotation.RPC rpc = BeanHelper.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class);
+TestAnnotation.RPC rpc = $.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class);
 // 获取Class的字段信息(此处为IdxController类)
-Map<String, BeanHelper.FieldInfo> fieldsInfo = BeanHelper.findFieldsInfo(IdxController.class, null, null, null, null);
+Map<String, $.bean.FieldInfo> fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, null);
 // 获取Class的方法信息(此处为IdxController类)
-List<BeanHelper.MethodInfo> methodsInfo = BeanHelper.findMethodsInfo(IdxController.class, null, null, null, null);
+List<$.bean.MethodInfo> methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, null);
 // 获取字段对应的Get/Set方法(此处为User类)
-Map<String, Method[]> rel = BeanHelper.parseRelFieldAndMethod(User.class, null, null, null, null);
+Map<String, Method[]> rel = $.bean.parseRelFieldAndMethod(User.class, null, null, null, null);
 User user = new User();
 user.setName("gudaoxuri");
 // 根据字段的Get方法获取对应的值
-Map<String, Object> values = BeanHelper.findValuesByRel(user, BeanHelper.parseRelFieldAndMethod(User.class, null, null, null, null));
+Map<String, Object> values = $.bean.findValuesByRel(user, $.bean.parseRelFieldAndMethod(User.class, null, null, null, null));
 // 获取对象所有字段的值
-values = BeanHelper.findValues(user, null, null, null, null);
+values = $.bean.findValues(user, null, null, null, null);
 // 根据字段名称获取对应的值(需要有标准的Get方法)
-Object value = BeanHelper.getValue(user, "name");
+Object value = $.bean.getValue(user, "name");
 // 根据字段名称设置值(需要有标准的Set方法)
-BeanHelper.setValue(user, "name", "gudaoxuri");
+$.bean.setValue(user, "name", "gudaoxuri");
@@ -625,13 +596,13 @@

-

1.2.3. Java Class扫描操作(ClassScanHelper)

+

Java Class扫描操作($.clazz)

// 扫描获取指定包下符合条件的class类(此处要求包含Deprecated注解)
-Set<Class<?>> resultInFile = ClassScanHelper.scan("com.ecfront.dew.common.test", new HashSet<Class<? extends Annotation>>(){{add(Deprecated.class);}},null);
+Set<Class<?>> resultInFile = $.clazz.scan("com.ecfront.$.common.test", new HashSet<Class<? extends Annotation>>(){{add(Deprecated.class);}},null);
 // 扫描获取指定包下符合条件的class类(此处要求包含Before\\w*类名)
-Set<Class<?>> resultInJar = ClassScanHelper.scan("org.junit",null, new HashSet<String>(){{add("Before\\w*");}});
+Set<Class<?>> resultInJar = $.clazz.scan("org.junit",null, new HashSet<String>(){{add("Before\\w*");}});
@@ -648,10 +619,10 @@

-

1.2.4. Shell脚本操作(ShellProcessor)

+

Shell脚本操作($.shell())

-
new ShellProcessor().execute(
+
$.shell().execute(
         "/opt/test.sh", //  sh文件路径,包含参数
         "test1", // 任务ID
         "done!", // 成功标识,只要捕捉到此标识就视为成功,为null时不会调用ReportHandler的success方法,执行结束后会调用ReportHandler的fail方法
@@ -691,42 +662,42 @@ 

-

1.2.5. 加解密操作(EncryptHelper)

+

加解密操作($.encrypt)

// 字符串 转 Base64
-String base64 = EncryptHelper.encodeStringToBase64("gudaoxuri", "UTF-8");
+String base64 = $.encrypt.encodeStringToBase64("gudaoxuri", "UTF-8");
 // 数组 转 Base64
-base64 = EncryptHelper.encodeBytesToBase64("gudaoxuri".getBytes(), "UTF-8");
+base64 = $.encrypt.encodeBytesToBase64("gudaoxuri".getBytes(), "UTF-8");
 // Base64 转 字符串
-String str = EncryptHelper.decodeBase64ToString(base64, "UTF-8");
+String str = $.encrypt.decodeBase64ToString(base64, "UTF-8");
 // Base64 转 字符串
-byte[] bytes = EncryptHelper.decodeBase64ToBytes(base64);
+byte[] bytes = $.encrypt.decodeBase64ToBytes(base64);
 
 // 对称加密(此处使用SHA-256算法,支持如bcrypt SHA-256 MD5等算法)
-String encrypt = EncryptHelper.Symmetric.encrypt("gudaoxuri", "SHA-256");
+String encrypt = $.encrypt.Symmetric.encrypt("gudaoxuri", "SHA-256");
 // 对称加密 - 验证(对于bcrypt之类默认使用随机slat的加密算法必须使用此方法验证)
-EncryptHelper.Symmetric.validate("gudaoxuri", encrypt, "SHA-256");
+$.encrypt.Symmetric.validate("gudaoxuri", encrypt, "SHA-256");
 
 // 非对称加密 - 生成公钥和私钥
-Map<String, String> keys = EncryptHelper.Asymmetric.generateKeys("RSA", 1024, "UTF-8");
+Map<String, String> keys = $.encrypt.Asymmetric.generateKeys("RSA", 1024, "UTF-8");
 String publicStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC47dAhLLB3xhDWccgEheqTbRimAhluN/ixNyYU/MvExN/bwytthiWViRV2H1sGrGr5JyH3qQSFa57jInbXD6lGN24aw2TfiejLWGkj0hMEXEtj4Bf9OuQhHUmy8unLygOuBlIhtfPLp9cSLBgVVHbt33buNTkL7fvdE2U9B3JVyQIDAQAB";
 // 非对称加密 - 获取公钥文件
-PublicKey publicKey = EncryptHelper.Asymmetric.getPublicKey(publicStr, "RSA");
+PublicKey publicKey = $.encrypt.Asymmetric.getPublicKey(publicStr, "RSA");
 String privateStr = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALjt0CEssHfGENZxyASF6pNtGKYCGW43+LE3JhT8y8TE39vDK22GJZWJFXYfWwasavknIfepBIVrnuMidtcPqUY3bhrDZN+J6MtYaSPSEwRcS2PgF/065CEdSbLy6cvKA64GUiG188un1xIsGBVUdu3fdu41OQvt+90TZT0HclXJAgMBAAECgYEAjXFndVhHCPU3P637PGppBqW06pREeybYUkNKH1dTS4cBaYcXmke2S290OMq2xp3tm++wbUqbKKkt97AOkWNrJfq8Ecpdw9s3c7yQGWaPuwiX38Cgtq6r0utjT20YgR6etGpqafoBt93RZpEm0eEzFPUnS7qYc86HprL0RJ0/i7kCQQDaOmvO82cYIK1ESkA0GdDVQoz2A1V8HvEWOsccRGqlWuasLUccyBnx1G/LDZUxcPOraDyxI8sdl7VbweLR0H9LAkEA2O/rWXwnSYKqdpt+OhpUBHNnMs3IMvRzefJ1zObnIMyYR3KXtpQ/fL4gEquNwJgFIaPJVg5/3zHISEw3e8XOuwJAIDrGl07tZ+vTiyVoLAmwBP8KMH83jdhIBN9zbqJQGdG+Bam+Oer3ofac+CEuapni8uq3I/ZEVj+EomOVKyWe1wJAATztROd2ee7q9h5RDBfWXughsKKH//JxLkL59R9kNkW0oMPApeQWsKmNGU4tUuoLLXP31CvlAusPz4nPzz8DvQJBAJXpICPNJw84fONzS0raRqlFoZMMI0cqeGtPIiCHKaRHyzQv/FFu2KxUcCrod8PngaBFRselzrwZILmXHqrHc1M=";
 // 非对称加密 - 获取私钥文件
-PrivateKey privateKey = EncryptHelper.Asymmetric.getPrivateKey(privateStr, "RSA");
+PrivateKey privateKey = $.encrypt.Asymmetric.getPrivateKey(privateStr, "RSA");
 
 String d = "Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。";
 // 非对称加密 - 公钥加密/私钥解密
-byte[] encryptByPub = EncryptHelper.Asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA");
-String result = new String(EncryptHelper.Asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8");
+byte[] encryptByPub = $.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA");
+String result = new String($.encrypt.Asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8");
 
 // 非对称加密 - 私钥加密/公钥解密
-byte[] encryptByPriv = EncryptHelper.Asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA");
-byte[] decryptByPub = EncryptHelper.Asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA");
-EncryptHelper.Asymmetric.verify(publicKey, decryptByPub,
-        EncryptHelper.Asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"),
+byte[] encryptByPriv = $.encrypt.Asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA");
+byte[] decryptByPub = $.encrypt.Asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA");
+$.encrypt.Asymmetric.verify(publicKey, decryptByPub,
+        $.encrypt.Asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"),
         "SHA1withRSA");
@@ -744,27 +715,27 @@

1.2

-

1.2.6. 通用拦截器栈(DewInterceptorProcessor)

+

通用拦截器栈($.interceptor)

// 没有注册拦截器的情况
-Resp<DewInterceptRespBody<Obj>> resp = DewInterceptorProcessor.process("none", new Obj("1"), new HashMap<>(), (obj, context) ->
+Resp<DewInterceptRespBody<Obj>> resp = $.interceptor.process("none", new Obj("1"), new HashMap<>(), (obj, context) ->
         Resp.success(DewInterceptRespBody.build(obj, context))
 );
 Assert.assertTrue(resp.ok());
 Assert.assertEquals("1", resp.getBody().getObj().getF());
 
 // 注册了一个拦截器A
-DewInterceptorProcessor.register("test", new InterceptorA());
-resp = DewInterceptorProcessor.process("test", new Obj("1"), new HashMap<>(), (obj, context) ->
+$.interceptor.register("test", new InterceptorA());
+resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) ->
         Resp.success(DewInterceptRespBody.build(obj, context))
 );
 Assert.assertTrue(resp.ok());
 Assert.assertEquals("3", resp.getBody().getObj().getF());
 
 // 注册了另一个拦截器B,假设B执行会报错
-DewInterceptorProcessor.register("test", new InterceptorB());
-resp = DewInterceptorProcessor.process("test", new Obj("1"), new HashMap<>(), (obj, context) ->
+$.interceptor.register("test", new InterceptorB());
+resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) ->
         Resp.success(DewInterceptRespBody.build(obj, context))
 );
 Assert.assertTrue(!resp.ok());
@@ -834,15 +805,15 @@ 

-

1.2.7. 定时器操作(TimerHelper)

+

定时器操作($.timer)

// 延迟任务
-TimerHelper.timer(1, () -> // Do Something);
+$.timer.timer(1, () -> // Do Something);
 // 周期性任务,参数 fixedRate 为true时表示每periodSec执行,为false表示fixedDelay,表示在当前任务执行完成后过periodSec再执行
-String taskId = TimerHelper.periodic(1, true, () -> // Do Something);
+String taskId = $.timer.periodic(1, true, () -> // Do Something);
 // 取消周期性任务
-TimerHelper.cancel(taskId);
+$.timer.cancel(taskId);
@@ -859,11 +830,11 @@

1.2.7.

-

1.2.8. 常用文件操作(FileHelper)

+

常用文件操作($.file)

// 根据classpath读取文件所有内容(jar包外路径优先),另外readAllByPath、readAllByFile、readAllByPathName等衍生方法
-String conf=FileHelper.readAllByClassPath("conf1.json","UTF-8");
+String conf=$.file.readAllByClassPath("conf1.json","UTF-8");
@@ -880,31 +851,31 @@

1.2.8.

-

1.2.9. 常用字段操作(FieldHelper)

+

常用字段操作($.field)

// 验证邮箱格式是否合法
-FieldHelper.validateEmail("i@sunisle.org");
+$.field.validateEmail("i@sunisle.org");
 // 验证手机号格式是否合法
-FieldHelper.validateMobile("18657120000");
+$.field.validateMobile("18657120000");
 // 是否是汉字
-FieldHelper.isChinese("孤岛旭日");
+$.field.isChinese("孤岛旭日");
 // 验证身份证是否合法
-FieldHelper.validateIdNumber("330102199901015759");
+$.field.validateIdNumber("330102199901015759");
 // 根据身份编号获取年龄
-FieldHelper.getAgeByIdCard("330102199901015759");
+$.field.getAgeByIdCard("330102199901015759");
 // 根据身份编号获取生日
-FieldHelper.getBirthByIdCard("330102199901015759");
+$.field.getBirthByIdCard("330102199901015759");
 // 根据身份编号获取生日年
-FieldHelper.getYearByIdCard("330102199901015759");
+$.field.getYearByIdCard("330102199901015759");
 // 根据身份编号获取生日月
-FieldHelper.getMonthByIdCard("330102199901015759");
+$.field.getMonthByIdCard("330102199901015759");
 // 根据身份编号获取生日天
-FieldHelper.getDateByIdCard("330102199901015759");
+$.field.getDateByIdCard("330102199901015759");
 // 根据身份编号获取性别
-FieldHelper.getGenderByIdCard("330102199901015759");
+$.field.getGenderByIdCard("330102199901015759");
 // 根据身份编号获取户籍省份
-FieldHelper.getProvinceByIdCard("330102199901015759");
+$.field.getProvinceByIdCard("330102199901015759");
@@ -921,7 +892,7 @@

1.2.9.

-

1.2.10. 响应处理模型(Resp)

+

响应处理模型(Resp)

@@ -1075,7 +1046,7 @@

1.2.10. 响应处理
-

1.2.11. 分页模型(PageDTO)

+

分页模型(PageDTO)

@@ -1124,8 +1095,7 @@

1.2.11. 分页 diff --git a/pom.xml b/pom.xml index 4a3f4bb..5c73ff8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ Dew公共模块 https://github.com/gudaoxuri/dew-common jar - 1.1.1 + 1.2.0 1.8 diff --git a/src/main/java/com/ecfront/dew/common/DEW.java b/src/main/java/com/ecfront/dew/common/$.java similarity index 93% rename from src/main/java/com/ecfront/dew/common/DEW.java rename to src/main/java/com/ecfront/dew/common/$.java index b7dfe40..006b7ce 100644 --- a/src/main/java/com/ecfront/dew/common/DEW.java +++ b/src/main/java/com/ecfront/dew/common/$.java @@ -1,11 +1,9 @@ package com.ecfront.dew.common; -import com.ecfront.dew.common.interceptor.DewInterceptorProcessor; - /** * DEW Common 操作入口 */ -public class DEW { +public class $ { /** * Json与Java对象互转 diff --git a/src/main/java/com/ecfront/dew/common/BeanHelper.java b/src/main/java/com/ecfront/dew/common/BeanHelper.java index 90c5d04..b2ddbd8 100644 --- a/src/main/java/com/ecfront/dew/common/BeanHelper.java +++ b/src/main/java/com/ecfront/dew/common/BeanHelper.java @@ -16,6 +16,8 @@ public class BeanHelper { private static NullAwareBeanUtilsBean copyPropertiesAdapter = new NullAwareBeanUtilsBean(); + BeanHelper(){} + /** * Java Bean Copy * diff --git a/src/main/java/com/ecfront/dew/common/ClassScanHelper.java b/src/main/java/com/ecfront/dew/common/ClassScanHelper.java index aaa52a4..b420c2d 100644 --- a/src/main/java/com/ecfront/dew/common/ClassScanHelper.java +++ b/src/main/java/com/ecfront/dew/common/ClassScanHelper.java @@ -19,6 +19,8 @@ */ public class ClassScanHelper { + ClassScanHelper(){} + /** * 扫描获取指定包下符合条件的class类 * diff --git a/src/main/java/com/ecfront/dew/common/interceptor/DewInterceptorProcessor.java b/src/main/java/com/ecfront/dew/common/DewInterceptorProcessor.java similarity index 93% rename from src/main/java/com/ecfront/dew/common/interceptor/DewInterceptorProcessor.java rename to src/main/java/com/ecfront/dew/common/DewInterceptorProcessor.java index cd2bb42..70e1526 100644 --- a/src/main/java/com/ecfront/dew/common/interceptor/DewInterceptorProcessor.java +++ b/src/main/java/com/ecfront/dew/common/DewInterceptorProcessor.java @@ -1,6 +1,8 @@ -package com.ecfront.dew.common.interceptor; +package com.ecfront.dew.common; -import com.ecfront.dew.common.Resp; +import com.ecfront.dew.common.interceptor.DewInterceptExec; +import com.ecfront.dew.common.interceptor.DewInterceptRespBody; +import com.ecfront.dew.common.interceptor.DewInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +20,9 @@ public class DewInterceptorProcessor { private static Map>> CONTAINER = new HashMap<>(); + DewInterceptorProcessor() { + } + /** * 注册拦截器栈 * diff --git a/src/main/java/com/ecfront/dew/common/EncryptHelper.java b/src/main/java/com/ecfront/dew/common/EncryptHelper.java index 44384af..b5075b9 100644 --- a/src/main/java/com/ecfront/dew/common/EncryptHelper.java +++ b/src/main/java/com/ecfront/dew/common/EncryptHelper.java @@ -23,6 +23,12 @@ */ public class EncryptHelper { + EncryptHelper() { + } + + public Symmetric symmetric = new Symmetric(); + public Asymmetric asymmetric = new Asymmetric(); + /** * Base64 转 数组 */ @@ -51,13 +57,10 @@ public String encodeStringToBase64(String str, String encode) throws Unsupported return new String(Base64.getEncoder().encode(str.getBytes(encode)), encode); } - public Symmetric symmetric = new Symmetric(); - public Asymmetric asymmetric = new Asymmetric(); - /** * 对称加密 */ - class Symmetric { + public class Symmetric { /** * 对称加密 @@ -110,7 +113,7 @@ public boolean validate(String strSrc, String strEncrypted, String algorithm) th /** * 非对称加密 */ - class Asymmetric { + public class Asymmetric { /** * 生成公钥和私钥 diff --git a/src/main/java/com/ecfront/dew/common/FieldHelper.java b/src/main/java/com/ecfront/dew/common/FieldHelper.java index ace1543..3f3c5e3 100644 --- a/src/main/java/com/ecfront/dew/common/FieldHelper.java +++ b/src/main/java/com/ecfront/dew/common/FieldHelper.java @@ -19,6 +19,8 @@ public class FieldHelper { Pattern.compile("^[\u4e00-\u9fa5]+$"); + FieldHelper(){} + /** * 验证邮箱格式是否合法 * diff --git a/src/main/java/com/ecfront/dew/common/FileHelper.java b/src/main/java/com/ecfront/dew/common/FileHelper.java index c86304b..1e8f0f7 100644 --- a/src/main/java/com/ecfront/dew/common/FileHelper.java +++ b/src/main/java/com/ecfront/dew/common/FileHelper.java @@ -11,6 +11,8 @@ */ public class FileHelper { + FileHelper(){} + /** * 根据文件路径名读取文件所有内容 * diff --git a/src/main/java/com/ecfront/dew/common/JsonHelper.java b/src/main/java/com/ecfront/dew/common/JsonHelper.java index cdb7cee..6b8730c 100644 --- a/src/main/java/com/ecfront/dew/common/JsonHelper.java +++ b/src/main/java/com/ecfront/dew/common/JsonHelper.java @@ -31,6 +31,8 @@ public class JsonHelper { setTimeZone(Calendar.getInstance().getTimeZone()); } + JsonHelper(){} + /** * 设置时区 * diff --git a/src/main/java/com/ecfront/dew/common/MimeHelper.java b/src/main/java/com/ecfront/dew/common/MimeHelper.java index 1c81d68..8f8f9ac 100644 --- a/src/main/java/com/ecfront/dew/common/MimeHelper.java +++ b/src/main/java/com/ecfront/dew/common/MimeHelper.java @@ -10,7 +10,9 @@ */ public class MimeHelper { - private Map> types = new HashMap>() {{ + MimeHelper(){} + + private static Map> types = new HashMap>() {{ put("office", new ArrayList() {{ add(Mime.TXT.toString()); add(Mime.DOC.toString()); diff --git a/src/main/java/com/ecfront/dew/common/Resp.java b/src/main/java/com/ecfront/dew/common/Resp.java index 71f25ff..e6c2e3d 100644 --- a/src/main/java/com/ecfront/dew/common/Resp.java +++ b/src/main/java/com/ecfront/dew/common/Resp.java @@ -211,7 +211,7 @@ public static Resp error(Resp resp) { public static Resp generic(Resp resp, Class bodyClazz) { E body = null; if (resp.ok() && resp.getBody() != null) { - body = DEW.json.toObject(resp.getBody(), bodyClazz); + body = $.json.toObject(resp.getBody(), bodyClazz); } return new Resp<>(resp.getCode(), resp.getMessage(), body); } @@ -226,7 +226,7 @@ public static Resp generic(Resp resp, Class bodyClazz) { public static Resp> genericList(Resp resp, Class bodyClazz) { List body = null; if (resp.ok() && resp.getBody() != null) { - body = DEW.json.toList(resp.getBody(), bodyClazz); + body = $.json.toList(resp.getBody(), bodyClazz); } return new Resp<>(resp.getCode(), resp.getMessage(), body); } @@ -241,8 +241,8 @@ public static Resp> genericList(Resp resp, Class bodyClazz) { public static Resp> genericPage(Resp resp, Class bodyClazz) { PageDTO body = null; if (resp.ok() && resp.getBody() != null) { - body = DEW.json.toObject(resp.getBody(), PageDTO.class); - body.setObjects(body.getObjects().stream().map(i -> DEW.json.toObject(i, bodyClazz)).collect(Collectors.toList())); + body = $.json.toObject(resp.getBody(), PageDTO.class); + body.setObjects(body.getObjects().stream().map(i -> $.json.toObject(i, bodyClazz)).collect(Collectors.toList())); } return new Resp<>(resp.getCode(), resp.getMessage(), body); } diff --git a/src/main/java/com/ecfront/dew/common/ShellProcessor.java b/src/main/java/com/ecfront/dew/common/ShellProcessor.java index 1081206..d58d7f5 100644 --- a/src/main/java/com/ecfront/dew/common/ShellProcessor.java +++ b/src/main/java/com/ecfront/dew/common/ShellProcessor.java @@ -18,6 +18,8 @@ public class ShellProcessor { private static final Logger logger = LoggerFactory.getLogger(ShellProcessor.class); + ShellProcessor(){} + private volatile String taskId; private volatile String successFlag; private volatile String progressFlag; diff --git a/src/main/java/com/ecfront/dew/common/TimeHelper.java b/src/main/java/com/ecfront/dew/common/TimeHelper.java index 595b59d..66ccc65 100644 --- a/src/main/java/com/ecfront/dew/common/TimeHelper.java +++ b/src/main/java/com/ecfront/dew/common/TimeHelper.java @@ -10,6 +10,8 @@ */ public class TimeHelper { + TimeHelper(){} + public final SimpleDateFormat msf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); public final SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); public final SimpleDateFormat mf = new SimpleDateFormat("yyyyMMddHHmm"); diff --git a/src/main/java/com/ecfront/dew/common/TimerHelper.java b/src/main/java/com/ecfront/dew/common/TimerHelper.java index 29c2fb3..056b3f0 100644 --- a/src/main/java/com/ecfront/dew/common/TimerHelper.java +++ b/src/main/java/com/ecfront/dew/common/TimerHelper.java @@ -16,6 +16,8 @@ public class TimerHelper { private static Map> CONTAINER = new HashMap<>(); + TimerHelper(){} + /** * 延迟执行的周期性任务 * diff --git a/src/test/java/com/ecfront/dew/common/BeanHelperTest.java b/src/test/java/com/ecfront/dew/common/BeanHelperTest.java index 41f74cd..0077c9e 100644 --- a/src/test/java/com/ecfront/dew/common/BeanHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/BeanHelperTest.java @@ -23,35 +23,35 @@ public void copyProperties() throws Exception { User dest = new User(); dest.setAge(11); dest.setWorkAge(11); - DEW.bean.copyProperties(dest, ori); + $.bean.copyProperties(dest, ori); Assert.assertTrue(Objects.equals(dest.getName(), "张三") && dest.getAge() == 0 && dest.getWorkAge() == 11); } @Test public void findClassAnnotation() throws Exception { - TestAnnotation.RPC ann = DEW.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class); + TestAnnotation.RPC ann = $.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class); Assert.assertEquals("/idx/", ann.path()); } @Test public void findFieldInfo() throws Exception { - Map fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, null, null); + Map fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, null); Assert.assertEquals(2, fieldsInfo.size()); - fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, new HashSet>() {{ + fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, new HashSet>() {{ add(Deprecated.class); }}, null, null); Assert.assertEquals(1, fieldsInfo.size()); - fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, new HashSet() {{ + fieldsInfo = $.bean.findFieldsInfo(IdxController.class, new HashSet() {{ add("parentField"); }}, new HashSet>() {{ add(Deprecated.class); }}, null, null); Assert.assertEquals(0, fieldsInfo.size()); - fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, null, new HashSet>() {{ + fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, new HashSet>() {{ add(Deprecated.class); }}); Assert.assertEquals(1, fieldsInfo.size()); - fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, new HashSet() {{ + fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, new HashSet() {{ add("parentField"); }}, new HashSet>() {{ add(Resource.class); @@ -61,23 +61,23 @@ public void findFieldInfo() throws Exception { @Test public void findMethodInfo() throws Exception { - List methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, null, null); + List methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, null); Assert.assertEquals(methodsInfo.size(), 7); - methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, new HashSet>() {{ + methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, new HashSet>() {{ add(TestAnnotation.GET.class); }}, null, null); Assert.assertEquals(methodsInfo.size(), 6); - methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, new HashSet() {{ + methodsInfo = $.bean.findMethodsInfo(IdxController.class, new HashSet() {{ add("find"); }}, new HashSet>() {{ add(TestAnnotation.GET.class); }}, null, null); Assert.assertEquals(methodsInfo.size(), 4); - methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, null, new HashSet>() {{ + methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, new HashSet>() {{ add(TestAnnotation.POST.class); }}); Assert.assertEquals(methodsInfo.size(), 3); - methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, new HashSet() {{ + methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, new HashSet() {{ add("childFind"); }}, new HashSet>() {{ add(TestAnnotation.POST.class); @@ -87,7 +87,7 @@ public void findMethodInfo() throws Exception { @Test public void parseRelFieldAndMethod() throws Exception { - Map rel = DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null); + Map rel = $.bean.parseRelFieldAndMethod(User.class, null, null, null, null); Assert.assertEquals(6, rel.size()); Assert.assertEquals(2, rel.get("enable").length); } @@ -96,7 +96,7 @@ public void parseRelFieldAndMethod() throws Exception { public void findValuesByRel() throws Exception { User user = new User(); user.setName("张三"); - Map values = DEW.bean.findValuesByRel(user, DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null)); + Map values = $.bean.findValuesByRel(user, $.bean.parseRelFieldAndMethod(User.class, null, null, null, null)); Assert.assertEquals("张三", values.get("name")); } @@ -104,7 +104,7 @@ public void findValuesByRel() throws Exception { public void findValues() throws Exception { User user = new User(); user.setName("张三"); - Map values = DEW.bean.findValues(user, null, null, null, null); + Map values = $.bean.findValues(user, null, null, null, null); Assert.assertEquals("张三", values.get("name")); } @@ -112,13 +112,13 @@ public void findValues() throws Exception { public void getValue() throws Exception { User user = new User(); user.setName("张三"); - Assert.assertEquals("张三", DEW.bean.getValue(user, "name")); + Assert.assertEquals("张三", $.bean.getValue(user, "name")); } @Test public void setValue() throws Exception { User user = new User(); - DEW.bean.setValue(user, "name", "张三"); + $.bean.setValue(user, "name", "张三"); Assert.assertEquals("张三", user.getName()); } diff --git a/src/test/java/com/ecfront/dew/common/ClassScanHelperTest.java b/src/test/java/com/ecfront/dew/common/ClassScanHelperTest.java index 938c663..166137f 100644 --- a/src/test/java/com/ecfront/dew/common/ClassScanHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/ClassScanHelperTest.java @@ -11,11 +11,11 @@ public class ClassScanHelperTest { @Test public void scan() throws Exception { - Set> resultInFile = DEW.clazz.scan("com.ecfront.dew.common.test", new HashSet>() {{ + Set> resultInFile = $.clazz.scan("com.ecfront.dew.common.test", new HashSet>() {{ add(Deprecated.class); }}, null); Assert.assertEquals(2, resultInFile.size()); - Set> resultInJar = DEW.clazz.scan("org.junit", null, new HashSet() {{ + Set> resultInJar = $.clazz.scan("org.junit", null, new HashSet() {{ add("Before\\w*"); }}); Assert.assertEquals(4, resultInJar.size()); diff --git a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java index 79dd680..7255d6a 100644 --- a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java @@ -13,9 +13,9 @@ public class EncryptHelperTest { @Test public void symmetric() throws Exception { Assert.assertEquals("70C0CC2B7BF8A8EBCD7B59C49DDDA9A1E551122BA5D7AB3B7B02141D4CE4C626".toLowerCase(), - DEW.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256")); - Assert.assertTrue(DEW.encrypt.symmetric.validate("gudaoxuri", DEW.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"), "SHA-256")); - Assert.assertTrue(DEW.encrypt.symmetric.validate("password", DEW.encrypt.symmetric.encrypt("password", "bcrypt"), "bcrypt")); + $.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256")); + Assert.assertTrue($.encrypt.symmetric.validate("gudaoxuri", $.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"), "SHA-256")); + Assert.assertTrue($.encrypt.symmetric.validate("password", $.encrypt.symmetric.encrypt("password", "bcrypt"), "bcrypt")); } @Test @@ -25,20 +25,20 @@ public void asymmetric() throws Exception { String d = "Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。"; // 生成公钥密钥 - Map keys = DEW.encrypt.asymmetric.generateKeys("RSA", 1024, "UTF-8"); - PublicKey publicKey = DEW.encrypt.asymmetric.getPublicKey(publicStr, "RSA"); - PrivateKey privateKey = DEW.encrypt.asymmetric.getPrivateKey(privateStr, "RSA"); + Map keys = $.encrypt.asymmetric.generateKeys("RSA", 1024, "UTF-8"); + PublicKey publicKey = $.encrypt.asymmetric.getPublicKey(publicStr, "RSA"); + PrivateKey privateKey = $.encrypt.asymmetric.getPrivateKey(privateStr, "RSA"); // 公钥加密/私钥解密 - byte[] encryptByPub = DEW.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA"); - String result = new String(DEW.encrypt.asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8"); + byte[] encryptByPub = $.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA"); + String result = new String($.encrypt.asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8"); Assert.assertTrue(Objects.equals(result, d)); // 私钥加密/公钥解密 - byte[] encryptByPriv = DEW.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA"); - byte[] decryptByPub = DEW.encrypt.asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA"); + byte[] encryptByPriv = $.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA"); + byte[] decryptByPub = $.encrypt.asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA"); Assert.assertTrue(Objects.equals(new String(decryptByPub, "UTF-8"), d)); - Assert.assertTrue(DEW.encrypt.asymmetric.verify(publicKey, decryptByPub, DEW.encrypt.asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA")); + Assert.assertTrue($.encrypt.asymmetric.verify(publicKey, decryptByPub, $.encrypt.asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA")); } } \ No newline at end of file diff --git a/src/test/java/com/ecfront/dew/common/FieldHelperTest.java b/src/test/java/com/ecfront/dew/common/FieldHelperTest.java index 471263f..f1e0f8b 100644 --- a/src/test/java/com/ecfront/dew/common/FieldHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/FieldHelperTest.java @@ -7,32 +7,32 @@ public class FieldHelperTest { @Test public void testField() throws Exception { - Assert.assertTrue(DEW.field.validateEmail("i@sunisle.org")); - Assert.assertTrue(DEW.field.validateEmail("fy53.org@gmail.com")); - Assert.assertFalse(DEW.field.validateEmail("i@sunisle")); - Assert.assertFalse(DEW.field.validateEmail("i@sunisle..org")); - Assert.assertFalse(DEW.field.validateEmail("@sunisle.org")); - Assert.assertFalse(DEW.field.validateEmail("i#sunisle.org")); - - Assert.assertTrue(DEW.field.validateMobile("18657120000")); - Assert.assertTrue(DEW.field.validateMobile("13765712000")); - Assert.assertTrue(DEW.field.validateMobile("17714712000")); - Assert.assertFalse(DEW.field.validateMobile("1865712000")); - Assert.assertFalse(DEW.field.validateMobile("28657120000")); - Assert.assertFalse(DEW.field.validateMobile("11657120000")); - - Assert.assertTrue(DEW.field.isChinese("孤岛旭日")); - Assert.assertFalse(DEW.field.isChinese("孤岛xuri")); - Assert.assertFalse(DEW.field.isChinese("gudaoxuri")); - - Assert.assertTrue(DEW.field.validateIdNumber("330102199901015759")); - Assert.assertEquals(18, DEW.field.getAgeByIdCard("330102199901015759")); - Assert.assertEquals("19990101", DEW.field.getBirthByIdCard("330102199901015759")); - Assert.assertEquals("M", DEW.field.getGenderByIdCard("330102199901015759")); - Assert.assertEquals("浙江", DEW.field.getProvinceByIdCard("330102199901015759")); - Assert.assertTrue(1 == DEW.field.getDateByIdCard("330102199901015759")); - Assert.assertTrue(1 == DEW.field.getMonthByIdCard("330102199901015759")); - Assert.assertTrue(1999 == DEW.field.getYearByIdCard("330102199901015759")); + Assert.assertTrue($.field.validateEmail("i@sunisle.org")); + Assert.assertTrue($.field.validateEmail("fy53.org@gmail.com")); + Assert.assertFalse($.field.validateEmail("i@sunisle")); + Assert.assertFalse($.field.validateEmail("i@sunisle..org")); + Assert.assertFalse($.field.validateEmail("@sunisle.org")); + Assert.assertFalse($.field.validateEmail("i#sunisle.org")); + + Assert.assertTrue($.field.validateMobile("18657120000")); + Assert.assertTrue($.field.validateMobile("13765712000")); + Assert.assertTrue($.field.validateMobile("17714712000")); + Assert.assertFalse($.field.validateMobile("1865712000")); + Assert.assertFalse($.field.validateMobile("28657120000")); + Assert.assertFalse($.field.validateMobile("11657120000")); + + Assert.assertTrue($.field.isChinese("孤岛旭日")); + Assert.assertFalse($.field.isChinese("孤岛xuri")); + Assert.assertFalse($.field.isChinese("gudaoxuri")); + + Assert.assertTrue($.field.validateIdNumber("330102199901015759")); + Assert.assertEquals(18, $.field.getAgeByIdCard("330102199901015759")); + Assert.assertEquals("19990101", $.field.getBirthByIdCard("330102199901015759")); + Assert.assertEquals("M", $.field.getGenderByIdCard("330102199901015759")); + Assert.assertEquals("浙江", $.field.getProvinceByIdCard("330102199901015759")); + Assert.assertTrue(1 == $.field.getDateByIdCard("330102199901015759")); + Assert.assertTrue(1 == $.field.getMonthByIdCard("330102199901015759")); + Assert.assertTrue(1999 == $.field.getYearByIdCard("330102199901015759")); } diff --git a/src/test/java/com/ecfront/dew/common/FileHelperTest.java b/src/test/java/com/ecfront/dew/common/FileHelperTest.java index 6adf48f..1f773e4 100644 --- a/src/test/java/com/ecfront/dew/common/FileHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/FileHelperTest.java @@ -7,9 +7,9 @@ public class FileHelperTest { @Test public void testFile() throws Exception { - String conf = DEW.file.readAllByClassPath("conf1.json", "UTF-8"); + String conf = $.file.readAllByClassPath("conf1.json", "UTF-8"); Assert.assertTrue(conf.contains("1")); - conf = DEW.file.readAllByClassPath("conf/conf2.json", "UTF-8"); + conf = $.file.readAllByClassPath("conf/conf2.json", "UTF-8"); Assert.assertTrue(conf.contains("2")); } diff --git a/src/test/java/com/ecfront/dew/common/InterceptorTest.java b/src/test/java/com/ecfront/dew/common/InterceptorTest.java index e1e7b78..096144c 100644 --- a/src/test/java/com/ecfront/dew/common/InterceptorTest.java +++ b/src/test/java/com/ecfront/dew/common/InterceptorTest.java @@ -13,21 +13,21 @@ public class InterceptorTest { @Test public void testInterceptor() throws Exception { // 没有注册拦截器的情况 - Resp> resp = DEW.interceptor.process("none", new Obj("1"), new HashMap<>(), (obj, context) -> + Resp> resp = $.interceptor.process("none", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(resp.ok()); Assert.assertEquals("1", resp.getBody().getObj().getF()); // 注册了一个拦截器A - DEW.interceptor.register("test", new InterceptorA()); - resp = DEW.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> + $.interceptor.register("test", new InterceptorA()); + resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(resp.ok()); Assert.assertEquals("3", resp.getBody().getObj().getF()); // 注册了另一个拦截器B,假设B执行会报错 - DEW.interceptor.register("test", new InterceptorB()); - resp = DEW.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> + $.interceptor.register("test", new InterceptorB()); + resp = $.interceptor.process("test", new Obj("1"), new HashMap<>(), (obj, context) -> Resp.success(DewInterceptRespBody.build(obj, context)) ); Assert.assertTrue(!resp.ok()); diff --git a/src/test/java/com/ecfront/dew/common/JsonHelperTest.java b/src/test/java/com/ecfront/dew/common/JsonHelperTest.java index 3e1e547..a13f0a7 100644 --- a/src/test/java/com/ecfront/dew/common/JsonHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/JsonHelperTest.java @@ -13,20 +13,20 @@ public class JsonHelperTest { public void toJsonString() throws Exception { Assert.assertEquals( "{\"\":{\"a_key\":\"a_val\"}}", - DEW.json.toJsonString(DEW.json.createObjectNode().set("", DEW.json.createObjectNode().put("a_key", "a_val")))); + $.json.toJsonString($.json.createObjectNode().set("", $.json.createObjectNode().put("a_key", "a_val")))); } @Test public void toJson() throws Exception { Assert.assertEquals("a_val", - DEW.json.toJson("{'a_key':'a_val'}").get("a_key").asText()); + $.json.toJson("{'a_key':'a_val'}").get("a_key").asText()); Assert.assertEquals("a_val", - DEW.json.toJson("{\r\n'a_key':'a_val' // 注释\r\n}").get("a_key").asText()); + $.json.toJson("{\r\n'a_key':'a_val' // 注释\r\n}").get("a_key").asText()); } @Test public void toList() throws Exception { - TestIdModel model = DEW.json.toList("[{'name':'sunisle','createTime':123456789,'cid':'1','date':'2016-07-12 12:00:00'}]", TestIdModel.class).get(0); + TestIdModel model = $.json.toList("[{'name':'sunisle','createTime':123456789,'cid':'1','date':'2016-07-12 12:00:00'}]", TestIdModel.class).get(0); Assert.assertEquals("sunisle", model.getName()); Assert.assertEquals("1", model.getCid()); Assert.assertEquals("123456789", model.getCreateTime()); @@ -35,7 +35,7 @@ public void toList() throws Exception { @Test public void toObject() throws Exception { - TestIdModel model = DEW.json.toObject("{'name':'sunisle','createTime':123456789,'cid':'1','date':'2016-07-12 12:00:00'}", TestIdModel.class); + TestIdModel model = $.json.toObject("{'name':'sunisle','createTime':123456789,'cid':'1','date':'2016-07-12 12:00:00'}", TestIdModel.class); Assert.assertEquals("sunisle", model.getName()); Assert.assertEquals("1", model.getCid()); Assert.assertEquals("123456789", model.getCreateTime()); diff --git a/src/test/java/com/ecfront/dew/common/ShellProcessorTest.java b/src/test/java/com/ecfront/dew/common/ShellProcessorTest.java index 2beacbf..4ec9795 100644 --- a/src/test/java/com/ecfront/dew/common/ShellProcessorTest.java +++ b/src/test/java/com/ecfront/dew/common/ShellProcessorTest.java @@ -6,7 +6,7 @@ public class ShellProcessorTest { @Test public void testShell() throws Exception { - DEW.shell().execute( + $.shell().execute( "/opt/test.sh", // sh文件路径,包含参数 "test1", // 任务ID "done!", // 成功标识,只要捕捉到此标识就视为成功,为null时不会调用ReportHandler的success方法,执行结束后会调用ReportHandler的fail方法 diff --git a/src/test/java/com/ecfront/dew/common/TimerHelperTest.java b/src/test/java/com/ecfront/dew/common/TimerHelperTest.java index b46abc2..9691051 100644 --- a/src/test/java/com/ecfront/dew/common/TimerHelperTest.java +++ b/src/test/java/com/ecfront/dew/common/TimerHelperTest.java @@ -8,12 +8,12 @@ public class TimerHelperTest { @Test public void testTimer() throws Exception { int[] i = {0}; - DEW.timer.timer(1, () -> Assert.assertEquals(1, i[0])); + $.timer.timer(1, () -> Assert.assertEquals(1, i[0])); i[0] = 1; - String taskId = DEW.timer.periodic(1, true, () -> i[0]++); + String taskId = $.timer.periodic(1, true, () -> i[0]++); Thread.sleep(1500); - DEW.timer.cancel(taskId); + $.timer.cancel(taskId); Thread.sleep(2000); Assert.assertEquals(3, i[0]); }