0) {
+ return TAR_GZ;
+ }
+ return fileName.substring(fileName.lastIndexOf(".") + 1);
+ }
+
+ // 判断文件是否存在
+ public static void judeFileExists(File file) {
+
+ if (file.exists()) {
+ System.out.println("file exists");
+ } else {
+ System.out.println("file not exists, create it ...");
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ *
+ * 判断文件夹是否存在, 不存在创建【采用mkdirs】
+ * 相关解释:
+ * 1、File类的createNewFile根据抽象路径创建一个新的空文件,当抽象路径制定的文件存在时,创建失败
+ * 2、File类的mkdir方法根据抽象路径创建目录
+ * 3、File类的mkdirs方法根据抽象路径创建目录,包括创建必需但不存在的父目录
+ * 4、File类的createTempFile方法创建临时文件,可以制定临时文件的文件名前缀、后缀及文件所在的目录,如果不指定目录,则存放在系统的临时文件夹下。
+ * 5、除mkdirs方法外,以上方法在创建文件和目录时,必须保证目标文件不存在,而且父目录存在,否则会创建失败
+ *
+ */
+ public static void judeDirExists(File file) {
+
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ System.out.println("dir exists");
+ } else {
+ System.out.println("the same name file exists, can not create dir");
+ }
+ } else {
+ System.out.println("dir not exists, create it ...");
+ file.mkdirs();
+ }
+
+ }
+
+}
diff --git a/src/main/java/com/yexuejc/base/util/IdcardValidator.java b/src/main/java/com/yexuejc/base/util/IdcardValidator.java
new file mode 100644
index 0000000..a13a6eb
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/IdcardValidator.java
@@ -0,0 +1,435 @@
+package com.yexuejc.base.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 校验身份证
+ *
+ * @author yexue
+ * @expl
+ * 15位身份证号码:第7、8位为出生年份(两位数),第9、10位为出生月份,第11、12位代表出生日期,第15位代表性别,奇数为男,偶数为女。
+ * 18位身份证号码:第7、8、9、10位为出生年份(四位数),第11、第12位为出生月份,第13、14位代表出生日期,第17位代表性别,奇数为男,偶数为女。
+ * 最后一位为校验位
+ *
+ * @time 2017年11月13日 下午5:27:09
+ */
+public class IdcardValidator {
+ private static final int LENGTH_15 = 15;
+ private static final int LENGTH_18 = 18;
+ private static final int LENGTH_2 = 2;
+ private static final String SEX_NAN = "男";
+
+ private IdcardValidator() {
+ }
+
+ /**
+ *
+ *
+ * 省、直辖市代码表:
+ * 11 : 北京 12 : 天津 13 : 河北 14 : 山西 15 : 内蒙古
+ * 21 : 辽宁 22 : 吉林 23 : 黑龙江 31 : 上海 32 : 江苏
+ * 33 : 浙江 34 : 安徽 35 : 福建 36 : 江西 37 : 山东
+ * 41 : 河南 42 : 湖北 43 : 湖南 44 : 广东 45 : 广西 46 : 海南
+ * 50 : 重庆 51 : 四川 52 : 贵州 53 : 云南 54 : 西藏
+ * 61 : 陕西 62 : 甘肃 63 : 青海 64 : 宁夏 65 : 新疆
+ * 71 : 台湾
+ * 81 : 香港 82 : 澳门
+ * 91 : 国外
+ *
+ */
+ private static String[] cityCode = {"11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35",
+ "36", "37", "41", "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65",
+ "71", "81", "82", "91"};
+
+ /**
+ * 每位加权因子
+ */
+ private static int power[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
+
+ /**
+ * 验证所有的身份证的合法性
+ *
+ * @param identity 身份证号
+ * @param sex 性别
+ * @return boolean
+ * @Title: isValidatedAllIdcard
+ * @Description: 验证所有的身份证的合法性
+ * @throw
+ */
+ public static boolean isValidatedAllIdcard(String identity, String sex) {
+ boolean b = isValidatedAllIdcard(identity);
+ if (b && identity.length() == LENGTH_18) {
+ b = false;
+ int char17 = Integer.parseInt(identity.substring(16, 17));
+ int i = 0;
+ if (SEX_NAN.equals(sex)) {
+ i = 1;
+ }
+ if ((char17 % LENGTH_2) == i) {
+ b = true;
+ }
+ }
+ return b;
+ }
+
+ /**
+ * 验证所有的身份证的合法性
+ *
+ * @param idcard 身份证
+ * @return 合法返回true,否则返回false
+ */
+ public static boolean isValidatedAllIdcard(String idcard) {
+ if (idcard == null || "".equals(idcard)) {
+ return false;
+ }
+ if (idcard.length() == LENGTH_15) {
+ return validate15IDCard(idcard);
+ }
+ return validate18Idcard(idcard);
+ }
+
+ /**
+ *
+ * 判断18位身份证的合法性
+ *
+ * 根据〖中华人民共和国国家标准GB11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。
+ * 排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
+ *
+ * 顺序码: 表示在同一地址码所标识的区域范围内,对同年、同月、同 日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配 给女性。
+ *
+ *
+ * 1.前1、2位数字表示:所在省份的代码; 2.第3、4位数字表示:所在城市的代码; 3.第5、6位数字表示:所在区县的代码;
+ * 4.第7~14位数字表示:出生年、月、日; 5.第15、16位数字表示:所在地的派出所的代码; 6.第17位数字表示性别:奇数表示男性,偶数表示女性;
+ * 7.第18位数字是校检码:也有的说是个人信息码,一般是随计算机的随机产生,用来检验身份证的正确性。校检码可以是0~9的数字,有时也用x表示。
+ *
+ *
+ * 第十八位数字(校验码)的计算方法为: 1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4 2 1
+ * 6 3 7 9 10 5 8 4 2
+ *
+ *
+ * 2.将这17位数字和系数相乘的结果相加。
+ *
+ *
+ * 3.用加出来和除以11,看余数是多少
+ *
+ * 4.余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2。
+ *
+ * 5.通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
+ *
+ *
+ * @param idcard
+ * @return
+ */
+ private static boolean validate18Idcard(String idcard) {
+ if (idcard == null) {
+ return false;
+ }
+
+ // 非18位为假
+ if (idcard.length() != LENGTH_18) {
+ return false;
+ }
+ // 获取前17位
+ String idcard17 = idcard.substring(0, 17);
+
+ // 前17位全部为数字
+ if (!isDigital(idcard17)) {
+ return false;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return false;
+ }
+
+ // 校验出生日期
+ String birthday = idcard.substring(6, 14);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+
+ try {
+ Date birthDate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthDate);
+ if (!tmpDate.equals(birthday)) {
+ // 出生年月日不正确
+ return false;
+ }
+
+ } catch (ParseException e1) {
+
+ return false;
+ }
+
+ // 获取第18位
+ String idcard18Code = idcard.substring(17, 18);
+
+ char c[] = idcard17.toCharArray();
+
+ int bit[] = converCharToInt(c);
+
+ int sum17 = 0;
+
+ sum17 = getPowerSum(bit);
+
+ // 将和值与11取模得到余数进行校验码判断
+ String checkCode = getCheckCodeBySum(sum17);
+ if (null == checkCode) {
+ return false;
+ }
+ // 将身份证的第18位与算出来的校码进行匹配,不相等就为假
+ if (!idcard18Code.equalsIgnoreCase(checkCode)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * 校验15位身份证
+ *
+ *
+ *
+ * 只校验省份和出生年月日
+ *
+ *
+ * @param idcard
+ * @return
+ */
+ private static boolean validate15IDCard(String idcard) {
+ if (idcard == null) {
+ return false;
+ }
+ // 非15位为假
+ if (idcard.length() != LENGTH_15) {
+ return false;
+ }
+
+ // 15全部为数字
+ if (!isDigital(idcard)) {
+ return false;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return false;
+ }
+
+ String birthday = idcard.substring(6, 12);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+
+ try {
+ Date birthDate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthDate);
+ if (!tmpDate.equals(birthday)) {
+ // 身份证日期错误
+ return false;
+ }
+
+ } catch (ParseException e1) {
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * 将15位的身份证转成18位身份证
+ *
+ * @param idcard
+ * @return
+ */
+ @SuppressWarnings("unused")
+ private static String convertIdcarBy15bit(String idcard) {
+ if (idcard == null) {
+ return null;
+ }
+
+ // 非15位身份证
+ if (idcard.length() != LENGTH_15) {
+ return null;
+ }
+
+ // 15全部为数字
+ if (!isDigital(idcard)) {
+ return null;
+ }
+
+ String provinceid = idcard.substring(0, 2);
+ // 校验省份
+ if (!checkProvinceid(provinceid)) {
+ return null;
+ }
+
+ String birthday = idcard.substring(6, 12);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+
+ Date birthdate = null;
+ try {
+ birthdate = sdf.parse(birthday);
+ String tmpDate = sdf.format(birthdate);
+ if (!tmpDate.equals(birthday)) {
+ // 身份证日期错误
+ return null;
+ }
+
+ } catch (ParseException e1) {
+ return null;
+ }
+
+ Calendar cday = Calendar.getInstance();
+ cday.setTime(birthdate);
+ String year = String.valueOf(cday.get(Calendar.YEAR));
+
+ String idcard17 = idcard.substring(0, 6) + year + idcard.substring(8);
+
+ char c[] = idcard17.toCharArray();
+ String checkCode = "";
+
+ // 将字符数组转为整型数组
+ int bit[] = converCharToInt(c);
+
+ int sum17 = 0;
+ sum17 = getPowerSum(bit);
+
+ // 获取和值与11取模得到余数进行校验码
+ checkCode = getCheckCodeBySum(sum17);
+
+ // 获取不到校验位
+ if (null == checkCode) {
+ return null;
+ }
+ // 将前17位与第18位校验码拼接
+ idcard17 += checkCode;
+ return idcard17;
+ }
+
+ /**
+ * 校验省份
+ *
+ * @param provinceid
+ * @return 合法返回TRUE,否则返回FALSE
+ */
+ private static boolean checkProvinceid(String provinceid) {
+ for (String id : cityCode) {
+ if (id.equals(provinceid)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 数字验证
+ *
+ * @param str
+ * @return
+ */
+ private static boolean isDigital(String str) {
+ return str.matches("^[0-9]*$");
+ }
+
+ /**
+ * 将身份证的每位和对应位的加权因子相乘之后,再得到和值
+ *
+ * @param bit
+ * @return
+ */
+ private static int getPowerSum(int[] bit) {
+
+ int sum = 0;
+
+ if (power.length != bit.length) {
+ return sum;
+ }
+
+ for (int i = 0; i < bit.length; i++) {
+ for (int j = 0; j < power.length; j++) {
+ if (i == j) {
+ sum = sum + bit[i] * power[j];
+ }
+ }
+ }
+ return sum;
+ }
+
+ /**
+ * 将和值与11取模得到余数进行校验码判断
+ *
+ * @param sum17
+ * @return 校验位
+ */
+ private static String getCheckCodeBySum(int sum17) {
+ String checkCode = null;
+ switch (sum17 % 11) {
+ case 10:
+ checkCode = "2";
+ break;
+ case 9:
+ checkCode = "3";
+ break;
+ case 8:
+ checkCode = "4";
+ break;
+ case 7:
+ checkCode = "5";
+ break;
+ case 6:
+ checkCode = "6";
+ break;
+ case 5:
+ checkCode = "7";
+ break;
+ case 4:
+ checkCode = "8";
+ break;
+ case 3:
+ checkCode = "9";
+ break;
+ case 2:
+ checkCode = "x";
+ break;
+ case 1:
+ checkCode = "0";
+ break;
+ case 0:
+ checkCode = "1";
+ break;
+ default:
+ break;
+ }
+ return checkCode;
+ }
+
+ /**
+ * 将字符数组转为整型数组
+ *
+ * @param c
+ * @return
+ * @throws NumberFormatException
+ */
+ private static int[] converCharToInt(char[] c) throws NumberFormatException {
+ int[] a = new int[c.length];
+ int k = 0;
+ for (char temp : c) {
+ a[k++] = Integer.parseInt(String.valueOf(temp));
+ }
+ return a;
+ }
+
+ /*
+ * public static void main(String[] args) throws Exception { String idcard15 =
+ * "130321860311519"; String idcard18 = "513002199410010816";//
+ * System.out.println(idcard18.substring(16,17)); // 15位身份证
+ * System.out.println(isValidatedAllIdcard(idcard15)); // 18位身份证
+ * System.out.println(isValidatedAllIdcard(idcard18)); // 15位身份证转18位身份证
+ * System.out.println(convertIdcarBy15bit(idcard15)); }
+ */
+}
\ No newline at end of file
diff --git a/src/main/java/com/yexuejc/base/util/JsonUtil.java b/src/main/java/com/yexuejc/base/util/JsonUtil.java
new file mode 100644
index 0000000..9b650da
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/JsonUtil.java
@@ -0,0 +1,146 @@
+package com.yexuejc.base.util;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class JsonUtil {
+ private JsonUtil() {
+ }
+
+ /**
+ * 作为单例全局使用
+ */
+ private static ObjectMapper objectMapper = new ObjectMapper();
+
+ static {
+ JsonUtil.initDefaultObjectMapper(JsonUtil.objectMapper);
+ }
+
+ /**
+ * 初始化ObjectMapper为默认属性
+ *
+ * @param objectMapper
+ */
+ private static void initDefaultObjectMapper(ObjectMapper objectMapper) {
+ objectMapper.setSerializationInclusion(Include.NON_NULL);
+ objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
+ objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+ objectMapper.setDateFormat(DateUtil.DATE_TIME_FORMAT);
+ }
+
+ /**
+ * 每调用一次生成一个全新的ObjectMapper供特殊场景使用,与通用ObjectMapper没有关系
+ *
+ * @return
+ */
+ public static ObjectMapper genObjectMapper() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonUtil.initDefaultObjectMapper(objectMapper);
+ return objectMapper;
+ }
+
+ /**
+ * 将json转换为某个类
+ *
+ * @param json InputStream类型json数据
+ * @param cls 转换类class
+ * @return 对象实例
+ */
+ public static T json2Obj(InputStream json, Class cls) {
+ T pojo = null;
+
+ try {
+ pojo = objectMapper.readValue(json, cls);
+ } catch (JsonParseException e) {
+ } catch (JsonMappingException e) {
+ } catch (IOException e) {
+ }
+
+ return pojo;
+ }
+
+ /**
+ * 将json转换为某个类
+ *
+ * @param json String类型json数据
+ * @param cls 转换类class
+ * @return 对象实例
+ */
+ public static T json2Obj(String json, Class cls) {
+ T pojo = null;
+
+ try {
+ pojo = objectMapper.readValue(json, cls);
+ } catch (JsonParseException e) {
+ } catch (JsonMappingException e) {
+ } catch (IOException e) {
+ }
+
+ return pojo;
+ }
+
+ /**
+ * Json字符串转换为Java对象
+ *
+ * @param json
+ * @param parametrized
+ * @param parameterClasses
+ * @return
+ */
+ public static T json2Obj(String json, Class parametrized, Class>... parameterClasses) {
+ T pojo = null;
+ JavaType javaType = objectMapper.getTypeFactory().constructParametrizedType(parametrized, parametrized,
+ parameterClasses);
+ try {
+ pojo = objectMapper.readValue(json, javaType);
+ } catch (JsonParseException e) {
+ } catch (JsonMappingException e) {
+ } catch (IOException e) {
+ }
+ return pojo;
+ }
+
+ /**
+ * Json字符串转换为Java对象
+ *
+ * @param json
+ * @param parametrized
+ * @param parameterClasses
+ * @return
+ */
+ public static T json2Obj(InputStream json, Class parametrized, Class>... parameterClasses) {
+ T pojo = null;
+ JavaType javaType = objectMapper.getTypeFactory().constructParametrizedType(parametrized, parametrized,
+ parameterClasses);
+ try {
+ pojo = objectMapper.readValue(json, javaType);
+ } catch (JsonParseException e) {
+ } catch (JsonMappingException e) {
+ } catch (IOException e) {
+ }
+ return pojo;
+ }
+
+ /**
+ * 将任何对象转换为json
+ *
+ * @param pojo 要转换的对象
+ * @return 返回json
+ */
+ public static String obj2Json(Object pojo) {
+ String json = null;
+ try {
+ json = objectMapper.writeValueAsString(pojo);
+ } catch (JsonProcessingException e) {
+ }
+ return json;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/yexuejc/base/util/JwtUtil.java b/src/main/java/com/yexuejc/base/util/JwtUtil.java
new file mode 100644
index 0000000..036016e
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/JwtUtil.java
@@ -0,0 +1,79 @@
+package com.yexuejc.base.util;
+
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+
+import java.util.Date;
+import java.util.Map;
+
+public class JwtUtil {
+ /** 加密用KEY */
+ private static String JWT_SIGNATURE_KEY = "h%OG8Y3WgA5AN7&6Ke7I#C1XvneW0N8a";
+ /** token类型 */
+ private static String JWT_HEADER_TYP = "JWT";
+ /** token发行商 */
+ private static String JWT_CLAIMS_ISS = "uselaw.com";
+
+ /**
+ * 加密内容生成token
+ *
+ * @param subjectObj
+ * @return
+ */
+ public static String compact(Object subjectObj) {
+ String subject = null;
+ if (subjectObj instanceof String) {
+ subject = (String) subjectObj;
+ } else {
+ subject = JsonUtil.obj2Json(subjectObj);
+ }
+ Date now = new Date();
+ String token = Jwts.builder()
+ // 设置token的唯一标识ID(claims.jti)
+ .setId(StrUtil.genUUID())
+ // 设置token类型(header.typ)
+ .setHeaderParam("typ", JWT_HEADER_TYP)
+ // 设置token发行时间为当前时间(claims.iat)
+ .setIssuedAt(now)
+ // 设置token发行商/发行者(claims.iss)
+ .setIssuer(JWT_CLAIMS_ISS)
+ // 设置token用户定义主体(claims.sub)
+ .setSubject(subject)
+ // 设置签名算法和KEY(signature)
+ .signWith(SignatureAlgorithm.HS512, JWT_SIGNATURE_KEY)
+ // 生成token
+ .compact();
+ return token;
+ }
+
+ /**
+ * 解密token为一个Map
+ *
+ * @param token
+ * @return
+ */
+ public static Map, ?> parse(String token) {
+ return parse(token, Map.class);
+ }
+
+ /**
+ * 解密token为一个指定对象
+ *
+ * @param token
+ * @param cls
+ * @return
+ */
+ public static T parse(String token, Class cls) {
+ String subject = null;
+ try {
+ subject = Jwts.parser().setSigningKey(JWT_SIGNATURE_KEY).parseClaimsJws(token).getBody().getSubject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (subject == null) {
+ return null;
+ }
+ return JsonUtil.json2Obj(subject, cls);
+ }
+
+}
diff --git a/src/main/java/com/yexuejc/base/util/MapRemoveNullUtil.java b/src/main/java/com/yexuejc/base/util/MapRemoveNullUtil.java
new file mode 100644
index 0000000..1442a8f
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/MapRemoveNullUtil.java
@@ -0,0 +1,116 @@
+package com.yexuejc.base.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+public class MapRemoveNullUtil {
+ private MapRemoveNullUtil() {
+ }
+
+
+ /**
+ * 移除map中空key或者value空值
+ *
+ * @param map
+ */
+ public static Map removeNullEntry(Map map) {
+ removeNullKey(map);
+ removeNullValue(map);
+ return map;
+ }
+
+ /**
+ * 移除map的空key
+ *
+ * @param map
+ * @return
+ */
+ public static Map removeNullKey(Map map) {
+ Set set = map.keySet();
+ for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
+ Object obj = (Object) iterator.next();
+ remove(obj, iterator);
+ }
+ return map;
+ }
+
+ /**
+ * 移除map中的value空值
+ *
+ * @param map
+ * @return
+ */
+ public static Map removeNullValue(Map map) {
+ Set set = map.keySet();
+ for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
+ Object obj = (Object) iterator.next();
+ Object value = (Object) map.get(obj);
+ remove(value, iterator);
+ }
+ return map;
+ }
+
+ /**
+ * Iterator 是工作在一个独立的线程中,并且拥有一个 mutex 锁。
+ * Iterator 被创建之后会建立一个指向原来对象的单链索引表,当原来的对象数量发生变化时,这个索引表的内容不会同步改变,
+ * 所以当索引指针往后移动的时候就找不到要迭代的对象,所以按照 fail-fast 原则 Iterator 会马上抛出 java.util.ConcurrentModificationException 异常。
+ * 所以 Iterator 在工作的时候是不允许被迭代的对象被改变的。
+ * 但你可以使用 Iterator 本身的方法 remove() 来删除对象, Iterator.remove() 方法会在删除当前迭代对象的同时维护索引的一致性。
+ *
+ * @param obj
+ * @param iterator
+ */
+ private static void remove(Object obj, Iterator iterator) {
+ if (obj instanceof String) {
+ String str = (String) obj;
+ if (StrUtil.isEmpty(str)) {
+ iterator.remove();
+ }
+ } else if (obj instanceof Collection) {
+ Collection col = (Collection) obj;
+ if (col == null || col.isEmpty()) {
+ iterator.remove();
+ }
+
+ } else if (obj instanceof Map) {
+ Map temp = (Map) obj;
+ if (temp == null || temp.isEmpty()) {
+ iterator.remove();
+ }
+
+ } else if (obj instanceof Object[]) {
+ Object[] array = (Object[]) obj;
+ if (array == null || array.length <= 0) {
+ iterator.remove();
+ }
+ } else {
+ if (obj == null) {
+ iterator.remove();
+ }
+ }
+ }
+
+
+// public static void main(String[] args) {
+// Map map = new HashMap();
+// map.put(1, "第一个值是数字");
+// map.put("2", "第2个值是字符串");
+// map.put(new String[]{"1","2"},"第3个值是数组");
+// map.put(new ArrayList(), "第4个值是List");
+// map.put(new HashMap(), "Map 无值");
+// map.put("5", "第5个");
+// map.put("6",null);
+// map.put("7", "");
+// map.put("8", " ");
+// System.out.println(map);
+// MapRemoveNullUtil.removeNullKey(map);
+// System.out.println();
+// System.out.println(map);
+// MapRemoveNullUtil.removeNullValue(map);
+// System.out.println();
+// System.out.println(map);
+// }
+
+}
diff --git a/src/main/java/com/yexuejc/base/util/MoneyUtils.java b/src/main/java/com/yexuejc/base/util/MoneyUtils.java
new file mode 100644
index 0000000..646dd80
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/MoneyUtils.java
@@ -0,0 +1,55 @@
+package com.yexuejc.base.util;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+/**
+ * q钱相关工具类
+ *
+ * @ClassName: MoneyUtils
+ * @Description:
+ * @author: maxf
+ * @date: 2017年12月1日 下午5:33:57
+ */
+public class MoneyUtils {
+ private MoneyUtils() {
+ }
+
+ /**
+ * 分转元
+ *
+ * @param num
+ * @return String
+ * @Title: formatPrice
+ * @Description:分转元
+ * @throw
+ */
+ public static String toYuan(Integer num) {
+ if (num == null) {
+ return "0.00";
+ }
+ DecimalFormat df = new DecimalFormat("0.00");
+ BigDecimal bigDecimal = new BigDecimal(num).divide(new BigDecimal(100));
+ String str = df.format(bigDecimal);
+ return str;
+ }
+
+ /**
+ * 元转分
+ *
+ * @param num
+ * @return int
+ * @Title: formatPrice
+ * @Description: 元转分
+ * @throw
+ */
+ public static int toFen(String num) {
+ if (num == null) {
+ return 0;
+ }
+ DecimalFormat df = new DecimalFormat("#0");
+ BigDecimal bigDecimal = new BigDecimal(num).multiply(new BigDecimal(100));
+ String str = df.format(bigDecimal);
+ return Integer.parseInt(str);
+ }
+}
diff --git a/src/main/java/com/yexuejc/base/util/RegexUtils.java b/src/main/java/com/yexuejc/base/util/RegexUtils.java
new file mode 100644
index 0000000..81d2cca
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/RegexUtils.java
@@ -0,0 +1,49 @@
+package com.yexuejc.base.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 正则验证
+ *
+ * @author yexue
+ * @expl
+ * @time 2017年11月9日 上午11:01:24
+ */
+public class RegexUtils {
+ private RegexUtils() {
+ }
+
+ /**
+ * 正则规则:小写字母
+ */
+ public static final String REGEX_LOWERCASE = "^$|^[a-z\\d_]+$";
+ /**
+ * 正则规则:中国人姓名
+ * 例:张三、买买提·也罗伊
+ */
+ public static final String CHINA_NAME = "^[\\u4e00-\\u9fa5]+(·[\\u4e00-\\u9fa5]+)*$";
+ ;
+ /**
+ * 短信验证码:4位数字
+ */
+ public static final String REGEX_NUM4 = "^$|^\\d{4}$";
+ /**
+ * cvn2:3位数字
+ */
+ public static final String REGEX_NUM3 = "^$|^\\d{3}$";
+
+ /**
+ * 正则:入参验证
+ *
+ * @param parms
+ * @param regex
+ * @return
+ */
+ public static boolean regex(String parms, String regex) {
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(parms);
+ return matcher.matches();
+ }
+
+}
diff --git a/src/main/java/com/yexuejc/base/util/StrUtil.java b/src/main/java/com/yexuejc/base/util/StrUtil.java
new file mode 100644
index 0000000..f556b4b
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/StrUtil.java
@@ -0,0 +1,195 @@
+package com.yexuejc.base.util;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static java.util.regex.Pattern.compile;
+
+/**
+ * @PackageName: com.yexuejc.util.base.util
+ * @Description:
+ * @author: maxf
+ * @date: 2017/12/28 17:34
+ */
+public final class StrUtil {
+ public static char[] HEX_CHAR = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
+ 'e', 'f'};
+
+ private StrUtil() {
+ }
+
+ public static boolean isEmpty(Object obj) {
+ if (obj instanceof String) {
+ return obj == null || "".equals((String) obj);
+ } else if (obj instanceof Object[]) {
+ return obj == null || ((Object[]) ((Object[]) obj)).length == 0;
+ } else if (obj instanceof Collection) {
+ return obj == null || ((Collection) obj).size() == 0;
+ } else {
+ return obj == null;
+ }
+ }
+
+ public static boolean isNotEmpty(Object obj) {
+ return !isEmpty(obj);
+ }
+
+ public static String genUUID() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
+ public static String genNum() {
+ int hashCode = UUID.randomUUID().toString().hashCode();
+ StringBuffer num = new StringBuffer();
+ if (hashCode < 0) {
+ hashCode = 0 - hashCode;
+ num.append("0");
+ } else {
+ num.append("1");
+ }
+
+ return num.append(String.format("%010d", hashCode)).toString().substring(0, 8);
+ }
+
+ public static Map parseUrlencoded(String urlencoded) {
+ if (isEmpty(urlencoded)) {
+ return null;
+ } else {
+ String[] entrys = urlencoded.split("&");
+ if (isEmpty(entrys)) {
+ return null;
+ } else {
+ Map map = new HashMap();
+ String[] kv = null;
+ String[] var4 = entrys;
+ int var5 = entrys.length;
+
+ for (int var6 = 0; var6 < var5; ++var6) {
+ String entry = var4[var6];
+ if (!isEmpty(entry)) {
+ kv = entry.split("=");
+ if (!isEmpty(kv)) {
+ if (kv.length > 1) {
+ map.put(kv[0], kv[1]);
+ } else {
+ map.put(kv[0], null);
+ }
+ }
+ }
+ }
+
+ return map;
+ }
+ }
+ }
+
+ public static String toHex(byte[] buf) {
+ StringBuffer strbuf = new StringBuffer(buf.length * 2);
+
+ for (int i = 0; i < buf.length; ++i) {
+ if ((buf[i] & 255) < 16) {
+ strbuf.append("0");
+ }
+
+ strbuf.append(Long.toString((long) (buf[i] & 255), 16));
+ }
+
+ return strbuf.toString();
+ }
+
+ public static String toMD5(String str) {
+ if (str == null) {
+ return null;
+ } else {
+ MessageDigest md = null;
+
+ try {
+ md = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException var3) {
+ var3.printStackTrace();
+ return null;
+ }
+
+ md.update(str.getBytes());
+ byte[] tmp = md.digest();
+ return toHex(tmp);
+ }
+ }
+
+ public static String iso2utf(String str) {
+ String utfStr = null;
+
+ try {
+ utfStr = new String(str.getBytes("ISO-8859-1"), "utf-8");
+ } catch (UnsupportedEncodingException var3) {
+ var3.printStackTrace();
+ }
+
+ return utfStr;
+ }
+
+ public static boolean isNumeric(String str) {
+ Pattern pattern = compile("[0-9]*");
+ Matcher isNum = pattern.matcher(str);
+ return isNum.matches();
+ }
+
+ public static String codeId(String id) {
+ if (id != null && id.length() == 32) {
+ StringBuilder coded = new StringBuilder();
+
+ int i;
+ for (i = 0; i < 13; ++i) {
+ coded.append(HEX_CHAR[(int) (Math.random() * 15.0D) + 1]);
+ }
+
+ coded.append(id.substring(0, 11));
+
+ for (i = 0; i < 7; ++i) {
+ coded.append(HEX_CHAR[(int) (Math.random() * 15.0D) + 1]);
+ }
+
+ coded.append(id.substring(11));
+
+ for (i = 0; i < 12; ++i) {
+ coded.append(HEX_CHAR[(int) (Math.random() * 15.0D) + 1]);
+ }
+
+ return coded.toString();
+ } else {
+ return id;
+ }
+ }
+
+ public static String decodeId(String coded) {
+ if (coded != null && coded.length() == 64) {
+ StringBuilder id = new StringBuilder();
+ id.append(coded.substring(13, 24));
+ id.append(coded.substring(31, 52));
+ return id.toString();
+ } else {
+ return coded;
+ }
+ }
+
+
+ /**
+ * 替换手机号中间4位为*
+ *
+ * @param mobile
+ * @return String
+ * @Title: replaceMobile
+ * @Description: 替换手机号中间4位为*
+ * @throw
+ */
+ public static String replaceMobile(String mobile) {
+ return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
+ }
+}
diff --git a/src/main/java/com/yexuejc/base/util/SysUtils.java b/src/main/java/com/yexuejc/base/util/SysUtils.java
new file mode 100644
index 0000000..2fd9fe9
--- /dev/null
+++ b/src/main/java/com/yexuejc/base/util/SysUtils.java
@@ -0,0 +1,25 @@
+package com.yexuejc.base.util;
+
+/**
+ * 系统工具类
+ *
+ * @PackageName: com.yexuejc.util.base
+ * @Description:
+ * @author: maxf
+ * @date: 2017/12/28 16:12
+ */
+public class SysUtils {
+ private static final String PROJECT_ROOT_PATH = "java.io.tmpdir";
+
+ private SysUtils() {
+ }
+
+ /**
+ * 获取临时缓存路径
+ *
+ * @return String
+ */
+ public static String getCachePath() {
+ return System.getProperty(PROJECT_ROOT_PATH);
+ }
+}