mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-22 18:36:52 +08:00
v1.1.0
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import net.lab1024.smartadmin.common.domain.BaseEnum;
|
||||
|
||||
/**
|
||||
* 枚举工具类
|
||||
*
|
||||
* @author listen
|
||||
* @date 2017/10/10 18:17
|
||||
*/
|
||||
public class SmartBaseEnumUtil {
|
||||
|
||||
/**
|
||||
* 校验int类型的参数与枚举类比较是否合法
|
||||
*
|
||||
* @param value 参数
|
||||
* @param enumClass 枚举类必须实现BaseEnum接口
|
||||
* @return boolean
|
||||
* @Author listen
|
||||
*/
|
||||
public static boolean checkEnum(Integer value, Class<? extends BaseEnum> enumClass) {
|
||||
if (null == value) {
|
||||
return false;
|
||||
}
|
||||
BaseEnum[] enums = enumClass.getEnumConstants();
|
||||
for (BaseEnum baseEnum : enums) {
|
||||
if (baseEnum.equalsValue(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举类的说明 value : info 的形式
|
||||
*
|
||||
* @param enumClass
|
||||
* @return String
|
||||
*/
|
||||
public static String getEnumDesc(Class<? extends BaseEnum> enumClass) {
|
||||
BaseEnum[] enums = enumClass.getEnumConstants();
|
||||
// value : info 的形式
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (BaseEnum baseEnum : enums) {
|
||||
sb.append(baseEnum.getValue() + ":" + baseEnum.getDesc() + ",");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取与int Code相匹配的枚举类的info
|
||||
*
|
||||
* @param value 参数
|
||||
* @param enumClass 枚举类必须实现BaseEnum接口
|
||||
* @return String 如无匹配枚举则返回null
|
||||
*/
|
||||
public static String getEnumDescByValue(Integer value, Class<? extends BaseEnum> enumClass) {
|
||||
BaseEnum[] enums = enumClass.getEnumConstants();
|
||||
for (BaseEnum baseEnum : enums) {
|
||||
if (baseEnum.equalsValue(value)) {
|
||||
return baseEnum.getDesc();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据int类型的参数与获取枚举类的实例
|
||||
*
|
||||
* @param value 参数
|
||||
* @param enumClass 枚举类必须实现BaseEnum接口
|
||||
* @return BaseEnum 无匹配值返回null
|
||||
* @Author listen
|
||||
*/
|
||||
public static <T extends BaseEnum> T getEnumByValue(Object value, Class<T> enumClass) {
|
||||
T[] enums = enumClass.getEnumConstants();
|
||||
for (T baseEnum : enums) {
|
||||
if (baseEnum.equalsValue(value)) {
|
||||
return baseEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SmartBeanUtil {
|
||||
|
||||
/**
|
||||
* 复制bean的属性
|
||||
*
|
||||
* @param source 源 要复制的对象
|
||||
* @param target 目标 复制到此对象
|
||||
*/
|
||||
public static void copyProperties(Object source, Object target) {
|
||||
BeanUtils.copyProperties(source, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制对象
|
||||
*
|
||||
* @param source 源 要复制的对象
|
||||
* @param target 目标 复制到此对象
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T copy(Object source, Class<T> target) {
|
||||
if(source == null || target == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
T newInstance = target.newInstance();
|
||||
BeanUtils.copyProperties(source, newInstance);
|
||||
return newInstance;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制list
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
* @param <T>
|
||||
* @param <K>
|
||||
* @return
|
||||
*/
|
||||
public static <T, K> List<K> copyList(List<T> source, Class<K> target) {
|
||||
|
||||
if (null == source || source.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return source.stream().map(e -> copy(e, target)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* 全局 BigDecimal 工具类
|
||||
*
|
||||
* @author listen
|
||||
* @date 2018/01/17 13:54
|
||||
*/
|
||||
public class SmartBigDecimalUtil {
|
||||
|
||||
/**
|
||||
* 价格类型 保留小数点 2
|
||||
*/
|
||||
public static final int PRICE_DECIMAL_POINT = 2;
|
||||
|
||||
/**
|
||||
* 价格类型 保留小数点 6
|
||||
*/
|
||||
public static final int SIX_PRICE_DECIMAL_POINT = 6;
|
||||
|
||||
/**
|
||||
* 重量类型保留小数点 3
|
||||
*/
|
||||
public static final int WEIGHT_DECIMAL_POINT = 3;
|
||||
|
||||
/**
|
||||
* 金额相关计算方法:四舍五入 保留2位小数点
|
||||
*/
|
||||
public static class Amount {
|
||||
|
||||
public static BigDecimal add(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.add(num2), PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal multiply(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.multiply(num2), PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal subtract(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.subtract(num2), PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal divide(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.divide(num2, RoundingMode.HALF_UP), PRICE_DECIMAL_POINT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额相关计算方法:四舍五入 保留2位小数点
|
||||
*/
|
||||
public static class AmountSix {
|
||||
|
||||
public static BigDecimal add(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.add(num2), SIX_PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal multiply(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.multiply(num2), SIX_PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal subtract(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.subtract(num2), SIX_PRICE_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal divide(BigDecimal num1, BigDecimal num2) {
|
||||
return num1.divide(num2, PRICE_DECIMAL_POINT, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重量相关计算方法:四舍五入 保留3位小数点
|
||||
*/
|
||||
public static class Weight {
|
||||
|
||||
public static BigDecimal add(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.add(num2), WEIGHT_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal multiply(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.multiply(num2), WEIGHT_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal subtract(BigDecimal num1, BigDecimal num2) {
|
||||
return setScale(num1.subtract(num2), WEIGHT_DECIMAL_POINT);
|
||||
}
|
||||
public static BigDecimal divide(BigDecimal num1, BigDecimal num2) {
|
||||
return num1.divide(num2, WEIGHT_DECIMAL_POINT, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BigDecimal 加法 num1 + num2
|
||||
* 未做非空校验
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 请使用BigDecimalUtils.PRICE_DECIMAL_POINT | BigDecimalUtils.WEIGHT_DECIMAL_POINT
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static BigDecimal add(BigDecimal num1, BigDecimal num2, int point) {
|
||||
return setScale(num1.add(num2), point);
|
||||
}
|
||||
|
||||
/**
|
||||
* BigDecimal 乘法 num1 x num2
|
||||
* 未做非空校验
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 请使用BigDecimalUtils.PRICE_DECIMAL_POINT | BigDecimalUtils.WEIGHT_DECIMAL_POINT
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static BigDecimal multiply(BigDecimal num1, BigDecimal num2, int point) {
|
||||
return setScale(num1.multiply(num2), point);
|
||||
}
|
||||
|
||||
/**
|
||||
* BigDecimal 减法 num1 - num2
|
||||
* 未做非空校验
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 请使用BigDecimalUtils.PRICE_DECIMAL_POINT | BigDecimalUtils.WEIGHT_DECIMAL_POINT
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static BigDecimal subtract(BigDecimal num1, BigDecimal num2, int point) {
|
||||
return setScale(num1.subtract(num2), point);
|
||||
}
|
||||
|
||||
/**
|
||||
* BigDecimal 除法 num1/num2
|
||||
* 未做非空校验
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 请使用BigDecimalUtils.PRICE_DECIMAL_POINT | BigDecimalUtils.WEIGHT_DECIMAL_POINT
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static BigDecimal divide(BigDecimal num1, BigDecimal num2, int point) {
|
||||
return num1.divide(num2, point, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置小数点类型为 四舍五入
|
||||
*
|
||||
* @param num
|
||||
* @param point
|
||||
* @return BigDecimal
|
||||
*/
|
||||
public static BigDecimal setScale(BigDecimal num, int point) {
|
||||
return num.setScale(point, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 num1 是否大于 num2
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isGreaterThan(BigDecimal num1, BigDecimal num2) {
|
||||
return num1.compareTo(num2) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 num1 是否大于等于 num2
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isGreaterOrEqual(BigDecimal num1, BigDecimal num2) {
|
||||
return isGreaterThan(num1, num2) || equals(num1, num2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 num1 是否小于 num2
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isLessThan(BigDecimal num1, BigDecimal num2) {
|
||||
return num1.compareTo(num2) == - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 num1 是否小于等于 num2
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isLessOrEqual(BigDecimal num1, BigDecimal num2) {
|
||||
return isLessThan(num1, num2) || equals(num1, num2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 num1 是否等于 num2
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return
|
||||
*/
|
||||
public static boolean equals(BigDecimal num1, BigDecimal num2) {
|
||||
return num1.compareTo(num2) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算 num1 / num2 的百分比
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @return String
|
||||
*/
|
||||
public static String getPercentage(BigDecimal num1, BigDecimal num2) {
|
||||
BigDecimal result = num1.divide(num2, 4, RoundingMode.HALF_UP);
|
||||
NumberFormat percent = NumberFormat.getPercentInstance();
|
||||
percent.setMaximumFractionDigits(2);
|
||||
return percent.format(result.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算 num1 / num2 的百分比
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 保留几位小数
|
||||
* @return String
|
||||
*/
|
||||
public static BigDecimal bigDecimalPercent(Integer num1, Integer num2, int point) {
|
||||
if (num1 == null || num2 == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (num2.equals(Integer.valueOf(0))) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal bigDecimalNum1 = new BigDecimal(num1);
|
||||
BigDecimal bigDecimalNum2 = new BigDecimal(num2);
|
||||
return bigDecimalPercent(bigDecimalNum1, bigDecimalNum2, point);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算 num1 / num2 的百分比
|
||||
*
|
||||
* @param num1
|
||||
* @param num2
|
||||
* @param point 保留几位小数
|
||||
* @return String
|
||||
*/
|
||||
public static BigDecimal bigDecimalPercent(BigDecimal num1, BigDecimal num2, int point) {
|
||||
if (num1 == null || num2 == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (equals(BigDecimal.ZERO, num2)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal percent = num1.divide(num2, point + 2, RoundingMode.HALF_UP);
|
||||
BigDecimal percent100 = percent.multiply(new BigDecimal(100)).setScale(point);
|
||||
return percent100;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断num是否为空 或者 零
|
||||
*
|
||||
* @param num
|
||||
* @return String
|
||||
*/
|
||||
public static Boolean isEmpty(BigDecimal num) {
|
||||
return null == num || equals(BigDecimal.ZERO, num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断num是否 不等于null 并且不等于零
|
||||
*
|
||||
* @param num
|
||||
* @return String
|
||||
*/
|
||||
public static Boolean isNotEmpty(BigDecimal num) {
|
||||
return ! isEmpty(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为万
|
||||
*
|
||||
* @param num
|
||||
* @param point
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal convertTenThousand(BigDecimal num, int point) {
|
||||
BigDecimal decimal = num.divide(new BigDecimal(10000), point, RoundingMode.HALF_UP);
|
||||
return decimal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为负数
|
||||
*
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal convertToMinusNumber(BigDecimal num) {
|
||||
if (isLessOrEqual(num, BigDecimal.ZERO)) {
|
||||
return num;
|
||||
}
|
||||
return BigDecimal.ZERO.subtract(num);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 线程安全的date工具类
|
||||
*
|
||||
* @author jiaozi
|
||||
*/
|
||||
public class SmartDateUtil extends DateUtils {
|
||||
|
||||
private static final ThreadLocal<DateFormats> dateFormats = new ThreadLocal<DateFormats>() {
|
||||
@Override
|
||||
protected DateFormats initialValue() {
|
||||
return new DateFormats();
|
||||
}
|
||||
};
|
||||
|
||||
public static final int HOUR_MIN = 60;
|
||||
|
||||
public static final int DAY_MI_SECOND = 24 * 60 * 60 * 1000;
|
||||
|
||||
public static String formatYMD(Date date) {
|
||||
return dateFormats.get().ymd.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDDigital(Date date) {
|
||||
return dateFormats.get().ymdDigital.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDHMSDigital(Date date) {
|
||||
return dateFormats.get().ymdhmsDigital.format(date);
|
||||
}
|
||||
|
||||
public static String formatYM(Date date) {
|
||||
return dateFormats.get().ym.format(date);
|
||||
}
|
||||
|
||||
public static String formatHMS(Date date) {
|
||||
return dateFormats.get().hms.format(date);
|
||||
}
|
||||
|
||||
public static String formatHM(Date date) {
|
||||
return dateFormats.get().hm.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDHM(Date date) {
|
||||
return dateFormats.get().ymdhm.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDHMS(Date date) {
|
||||
return dateFormats.get().ymdhms.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDChinese(Date date) {
|
||||
return dateFormats.get().ymdChinese.format(date);
|
||||
}
|
||||
|
||||
public static String formatYMDSlash(Date date) {
|
||||
return dateFormats.get().ymdSlash.format(date);
|
||||
}
|
||||
|
||||
public static Date parseYMD(String dateStr) {
|
||||
return parse(dateFormats.get().ymd, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseYMDDigital(String dateStr) {
|
||||
return parse(dateFormats.get().ymdDigital, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseYMDHMSDigital(String dateStr) {
|
||||
return parse(dateFormats.get().ymdhmsDigital, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseformatYMDChinese(String dateStr) {
|
||||
return parse(dateFormats.get().ymdChinese, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseYM(String dateStr) {
|
||||
return parse(dateFormats.get().ym, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseYMDHMS(String dateStr) {
|
||||
|
||||
return parse(dateFormats.get().ymdhms, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseYMDHM(String dateStr) {
|
||||
return parse(dateFormats.get().ymdhm, dateStr);
|
||||
}
|
||||
|
||||
public static Date parseTodayHMS(String dateStr) {
|
||||
String today = formatYMD(new Date());
|
||||
String todayDateStr = String.format("%s %s", today, dateStr);
|
||||
return parse(dateFormats.get().ymdhms, todayDateStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前时间是否在某段时间内 参数不区分先后顺序
|
||||
*/
|
||||
public static boolean isDuringTwoDate(Date date, Date another) {
|
||||
long dateTime = date.getTime();
|
||||
long anotherTime = another.getTime();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
if (currentTime > dateTime && currentTime < anotherTime) {
|
||||
return true;
|
||||
} else if (currentTime > anotherTime && currentTime < dateTime) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Date parse(SimpleDateFormat format, String dateStr) {
|
||||
try {
|
||||
Date d = format.parse(dateStr);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(d);
|
||||
int year = c.get(Calendar.YEAR);
|
||||
if (year >= 1000 && year <= 9999) {
|
||||
return d;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long daysOffset(Date date1, Date date2) {
|
||||
date1 = parseYMD(formatYMD(date1));
|
||||
date2 = parseYMD(formatYMD(date2));
|
||||
return (date1.getTime() - date2.getTime()) / DAY_MI_SECOND;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今天是星期几 , 7表示星期日
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getTodayDayOfWeek() {
|
||||
Calendar now = Calendar.getInstance();
|
||||
int dayOfweek = now.get(Calendar.DAY_OF_WEEK);
|
||||
dayOfweek--;
|
||||
if (dayOfweek == 0) {
|
||||
dayOfweek = 7;
|
||||
}
|
||||
return dayOfweek;
|
||||
}
|
||||
|
||||
public static boolean isTodaytDay(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
Calendar todayCalendar = Calendar.getInstance();
|
||||
if (calendar.get(Calendar.YEAR) != todayCalendar.get(Calendar.YEAR)) {
|
||||
return false;
|
||||
} else if (calendar.get(Calendar.MONTH) != todayCalendar.get(Calendar.MONTH)) {
|
||||
return false;
|
||||
} else if (calendar.get(Calendar.DAY_OF_MONTH) != todayCalendar.get(Calendar.DAY_OF_MONTH)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Calendar的小时、分钟、秒、毫秒
|
||||
*
|
||||
* @param calendar 日历
|
||||
* @param hour 小时
|
||||
* @param minute 分钟
|
||||
* @param second 秒
|
||||
* @param milliSecond 毫秒
|
||||
*/
|
||||
public static void setCalender(Calendar calendar, int hour, int minute, int second, int milliSecond) {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
calendar.set(Calendar.SECOND, second);
|
||||
calendar.set(Calendar.MILLISECOND, milliSecond);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定天开始时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 获得该日期的开始
|
||||
*/
|
||||
public static Date getDayBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, 0, 0, 0, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定天结束时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 获得该日期的结束
|
||||
*/
|
||||
public static Date getDayEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, 23, 59, 59, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该日期当月第一天
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static Date getMonthBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(getDayBegin(date));
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该日期当月最后一天getAgeByBirthday
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static Date getMonthEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(getDayEnd(date));
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, - 1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static String timeDifference(Date endDate) {
|
||||
Date nowDate = new Date();
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = nowDate.getTime() - endDate.getTime();
|
||||
// 计算差多少天
|
||||
long day = diff / nd;
|
||||
if (day > 0) {
|
||||
return day + "天前";
|
||||
}
|
||||
// 计算差多少小时
|
||||
long hour = diff % nd / nh;
|
||||
if (hour > 0) {
|
||||
return hour + "小时前";
|
||||
}
|
||||
// 计算差多少分钟
|
||||
long min = diff % nd % nh / nm;
|
||||
if (min > 0) {
|
||||
return "1小时内";
|
||||
}
|
||||
return "1小时内";
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算所用时长
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal timeDifferenceMin(Date startDate, Date endDate) {
|
||||
long nm = 1000 * 60;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = endDate.getTime() - startDate.getTime();
|
||||
BigDecimal min = BigDecimal.valueOf(diff).divide(BigDecimal.valueOf(nm), RoundingMode.HALF_UP);
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述: 是否为当天
|
||||
*
|
||||
* @param dateStr yyyy-mm-dd
|
||||
* @return
|
||||
* @auther yandanyang
|
||||
* @date 2018/10/16 0016 下午 17:43
|
||||
*/
|
||||
public static boolean isCurrentDayYMD(String dateStr) {
|
||||
if (StringUtils.isEmpty(dateStr)) {
|
||||
return true;
|
||||
}
|
||||
String current = SmartDateUtil.formatYMD(new Date());
|
||||
if (current.equals(dateStr)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述: 是否为当月
|
||||
*
|
||||
* @param dateStr yyyy-mm-dd
|
||||
* @return
|
||||
* @auther yandanyang
|
||||
* @date 2018/10/16 0016 下午 17:43
|
||||
*/
|
||||
public static boolean isCurrentMonthYMD(String dateStr) {
|
||||
if (StringUtils.isEmpty(dateStr)) {
|
||||
return true;
|
||||
}
|
||||
String queryDate = SmartDateUtil.formatYM(SmartDateUtil.parseYMD(dateStr));
|
||||
String current = SmartDateUtil.formatYM(new Date());
|
||||
if (current.equals(queryDate)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCurrentMonthYM(String dateStr) {
|
||||
if (StringUtils.isEmpty(dateStr)) {
|
||||
return true;
|
||||
}
|
||||
String current = SmartDateUtil.formatYM(new Date());
|
||||
if (current.equals(dateStr)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周的开始时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date getBeginDayOfWeek() {
|
||||
Date date = new Date();
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
|
||||
if (dayofweek == 1) {
|
||||
dayofweek += 7;
|
||||
}
|
||||
cal.add(Calendar.DATE, 2 - dayofweek);
|
||||
return getDayBegin(cal.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本周的结束时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date getEndDayOfWeek() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(getBeginDayOfWeek());
|
||||
cal.add(Calendar.DAY_OF_WEEK, 6);
|
||||
Date weekEndSta = cal.getTime();
|
||||
return getDayEnd(weekEndSta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个日期区间的日期(包括这两个日期)
|
||||
*/
|
||||
public static List<String> getiIntervalDate(String dateBegin, String dateEnd) {
|
||||
List<String> dateList = new ArrayList<>();
|
||||
Date startDate = SmartDateUtil.parseYMD(dateBegin);
|
||||
Date endDate = SmartDateUtil.parseYMD(dateEnd);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(startDate);
|
||||
dateList.add(dateBegin);
|
||||
while (cal.getTime().compareTo(endDate) < 0) {
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
dateList.add(SmartDateUtil.formatYMD(cal.getTime()));
|
||||
}
|
||||
return dateList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回某个日期后几天的日期
|
||||
*
|
||||
* @param date
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static Date getNextDay(Date date, int i) {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
cal.set(Calendar.DATE, cal.get(Calendar.DATE) + i);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回某个日期前几天的日期
|
||||
*
|
||||
* @param date
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static Date getFrontDay(Date date, int i) {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(date);
|
||||
cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨天的开始时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date getBeginDayOfYesterday() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayBegin(new Date()));
|
||||
cal.add(Calendar.DAY_OF_MONTH, - 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨天的结束时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date getEndDayOfYesterDay() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTime(getDayEnd(new Date()));
|
||||
cal.add(Calendar.DAY_OF_MONTH, - 1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public static Integer getDayNumOfMonth(Date date) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
Integer num = c.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换日期(格式:年-月-日 时:分--分自定义)
|
||||
*/
|
||||
public static String formatYMDH(Date date, String minute) {
|
||||
String ymdhm = dateFormats.get().ymdh + ":" + minute;
|
||||
SimpleDateFormat format = new SimpleDateFormat(ymdhm);
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取几个月后的日期
|
||||
*/
|
||||
public static Date getAfterMonth(Date inputDate, int number) {
|
||||
Calendar c = Calendar.getInstance();//获得一个日历的实例
|
||||
c.setTime(inputDate);//设置日历时间
|
||||
c.add(Calendar.MONTH, number);//在日历的月份上增加月
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算当前月有多少天
|
||||
*/
|
||||
public static int getDays(int year, int month) {
|
||||
int days = 0;
|
||||
if (month != 2) {
|
||||
switch (month) {
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
days = 31;
|
||||
break;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
days = 30;
|
||||
|
||||
}
|
||||
} else {
|
||||
// 闰年
|
||||
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||||
days = 29;
|
||||
} else {
|
||||
days = 28;
|
||||
}
|
||||
}
|
||||
System.out.println("当月有" + days + "天!");
|
||||
return days;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DateFormats {
|
||||
|
||||
public final SimpleDateFormat hms = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
public final SimpleDateFormat hm = new SimpleDateFormat("HH:mm");
|
||||
|
||||
public final SimpleDateFormat ymdhm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
|
||||
public final SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
public final SimpleDateFormat ym = new SimpleDateFormat("yyyy-MM");
|
||||
|
||||
public final SimpleDateFormat ymdhms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public final SimpleDateFormat ymdChinese = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
|
||||
public final SimpleDateFormat ymdSlash = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
public final SimpleDateFormat ymdDigital = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
public final SimpleDateFormat ymdhmsDigital = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
|
||||
public static final String ymdh = "yyyy-MM-dd HH";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
public class SmartDigestUtil extends DigestUtils {
|
||||
|
||||
/**
|
||||
* md5加盐加密
|
||||
*
|
||||
* @param salt
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String encryptPassword(String salt, String password) {
|
||||
return SmartDigestUtil.md5Hex(String.format(salt, password));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* @author: zhuoda
|
||||
* @create: 2020-03-30 14:27 PM from win10
|
||||
*/
|
||||
|
||||
public class SmartEasyPoiExcelUtil {
|
||||
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass,
|
||||
String fileName, boolean isCreateHeader, HttpServletResponse response) throws IOException {
|
||||
ExportParams exportParams = new ExportParams(title, sheetName);
|
||||
exportParams.setCreateHeadRows(isCreateHeader);
|
||||
defaultExport(list, pojoClass, fileName, response, exportParams);
|
||||
}
|
||||
|
||||
public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
|
||||
HttpServletResponse response) throws IOException {
|
||||
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
|
||||
}
|
||||
|
||||
public static void exportExcel(List<Map<String, Object>> list, String fileName, HttpServletResponse response) throws IOException {
|
||||
defaultExport(list, fileName, response);
|
||||
}
|
||||
|
||||
private static void defaultExport(List<?> list, Class<?> pojoClass, String fileName,
|
||||
HttpServletResponse response, ExportParams exportParams) throws IOException {
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
|
||||
if (workbook != null) ;
|
||||
downLoadExcel(fileName, response, workbook);
|
||||
}
|
||||
|
||||
private static void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) throws IOException {
|
||||
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
workbook.write(response.getOutputStream());
|
||||
}
|
||||
|
||||
private static void defaultExport(List<Map<String, Object>> list, String fileName, HttpServletResponse response) throws IOException {
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(list, ExcelType.HSSF);
|
||||
if (workbook != null) ;
|
||||
downLoadExcel(fileName, response, workbook);
|
||||
}
|
||||
|
||||
public static <T> List<T> importExcel(String filePath, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = null;
|
||||
try {
|
||||
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
|
||||
} catch (NoSuchElementException e) {
|
||||
//throw new NormalException("模板不能为空");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//throw new NormalException(e.getMessage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class<T> pojoClass) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(titleRows);
|
||||
params.setHeadRows(headerRows);
|
||||
List<T> list = null;
|
||||
try {
|
||||
list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params);
|
||||
} catch (NoSuchElementException e) {
|
||||
// throw new NormalException("excel文件不能为空");
|
||||
} catch (Exception e) {
|
||||
//throw new NormalException(e.getMessage());
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* [ HttpUtils ]
|
||||
*
|
||||
* @author yandanyang
|
||||
* @version 1.0
|
||||
* @company 1024lab.net
|
||||
* @copyright (c) 2019 1024lab.netInc. All rights reserved.
|
||||
* @date
|
||||
* @since JDK1.8
|
||||
*/
|
||||
public class SmartHttpUtil {
|
||||
|
||||
public static String sendGet(String url, Map<String, String> params, Map<String, String> header) throws Exception {
|
||||
HttpGet httpGet = null;
|
||||
String body = "";
|
||||
try {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
List<String> mapList = new ArrayList<>();
|
||||
if (params != null) {
|
||||
for (Entry<String, String> entry : params.entrySet()) {
|
||||
mapList.add(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(mapList)) {
|
||||
url = url + "?";
|
||||
String paramsStr = StringUtils.join(mapList, "&");
|
||||
url = url + paramsStr;
|
||||
}
|
||||
httpGet = new HttpGet(url);
|
||||
httpGet.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
httpGet.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
if (header != null) {
|
||||
for (Entry<String, String> entry : header.entrySet()) {
|
||||
httpGet.setHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
HttpResponse response = httpClient.execute(httpGet);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException("请求失败");
|
||||
} else {
|
||||
body = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (httpGet != null) {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
public static String sendPostJson(String url, String json, Map<String, String> header) throws Exception {
|
||||
HttpPost httpPost = null;
|
||||
String body = "";
|
||||
try {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
httpPost = new HttpPost(url);
|
||||
httpPost.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
if (header != null) {
|
||||
for (Entry<String, String> entry : header.entrySet()) {
|
||||
httpPost.setHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
StringEntity entity = new StringEntity(json, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException("请求失败");
|
||||
} else {
|
||||
body = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (httpPost != null) {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
public static String sendPostForm(String url, Map<String, String> params, Map<String, String> header) throws Exception {
|
||||
HttpPost httpPost = null;
|
||||
String body = "";
|
||||
try {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
httpPost = new HttpPost(url);
|
||||
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
if (header != null) {
|
||||
for (Entry<String, String> entry : header.entrySet()) {
|
||||
httpPost.setHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
List<NameValuePair> nvps = new ArrayList<>();
|
||||
if (params != null) {
|
||||
for (Entry<String, String> entry : params.entrySet()) {
|
||||
nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
//设置参数到请求对象中
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
throw new RuntimeException("请求失败");
|
||||
} else {
|
||||
body = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (httpPost != null) {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* [ ]
|
||||
*
|
||||
* @author yandanyang
|
||||
* @version 1.0
|
||||
* @company 1024lab.net
|
||||
* @copyright (c) 2018 1024lab.netInc. All rights reserved.
|
||||
* @date 2019/5/5 0005 下午 15:34
|
||||
* @since JDK1.8
|
||||
*/
|
||||
public class SmartIPUtil {
|
||||
|
||||
public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";
|
||||
|
||||
public static String getLocalHostIP() {
|
||||
// 本地IP,如果没有配置外网IP则返回它
|
||||
String localIp = null;
|
||||
// 外网IP
|
||||
String netIp = null;
|
||||
try {
|
||||
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
InetAddress ip = null;
|
||||
// 是否找到外网IP
|
||||
boolean finded = false;
|
||||
while (netInterfaces.hasMoreElements() && ! finded) {
|
||||
NetworkInterface ni = netInterfaces.nextElement();
|
||||
Enumeration<InetAddress> address = ni.getInetAddresses();
|
||||
while (address.hasMoreElements()) {
|
||||
ip = address.nextElement();
|
||||
// 外网IP
|
||||
if (! ip.isSiteLocalAddress() && ! ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == - 1) {
|
||||
netIp = ip.getHostAddress();
|
||||
finded = true;
|
||||
break;
|
||||
} else if (ip.isSiteLocalAddress() && ! ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == - 1) {
|
||||
// 内网IP
|
||||
localIp = ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
if (netIp != null && ! "".equals(netIp)) {
|
||||
return netIp;
|
||||
} else {
|
||||
return localIp;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getRemoteIp(HttpServletRequest request) {
|
||||
// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
|
||||
|
||||
String ip = getXForwardedForIp(request);
|
||||
if (ipValid(ip)) {
|
||||
return realIp(ip);
|
||||
}
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
if (ipValid(ip)) {
|
||||
return realIp(ip);
|
||||
}
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
if (ipValid(ip)) {
|
||||
return realIp(ip);
|
||||
}
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
if (ipValid(ip)) {
|
||||
return realIp(ip);
|
||||
}
|
||||
|
||||
ip = request.getRemoteAddr();
|
||||
return realIp(ip);
|
||||
}
|
||||
|
||||
private static String getXForwardedForIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
//ip 无效直接返回
|
||||
if (! ipValid(ip)) {
|
||||
return "";
|
||||
}
|
||||
if (ip.length() > 15) {
|
||||
String[] ips = ip.split(",");
|
||||
for (String strIp : ips) {
|
||||
if (! ("unknown".equalsIgnoreCase(strIp))) {
|
||||
ip = strIp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
private static Boolean ipValid(String ip) {
|
||||
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String realIp(String ip) {
|
||||
if (StringUtils.isEmpty(ip)) {
|
||||
return "";
|
||||
}
|
||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
||||
}
|
||||
|
||||
public static String getRemoteLocation(HttpServletRequest request) {
|
||||
String ip = getRemoteIp(request);
|
||||
return getIpLocation(ip);
|
||||
}
|
||||
|
||||
public static String getIpLocation(String ip) {
|
||||
String location = "未知";
|
||||
if (StringUtils.isEmpty(ip)) {
|
||||
return location;
|
||||
}
|
||||
Map<String, String> param = new HashMap<>();
|
||||
param.put("ip", ip);
|
||||
|
||||
try {
|
||||
String rspStr = SmartHttpUtil.sendGet(IP_URL, param, null);
|
||||
if (StringUtils.isEmpty(rspStr)) {
|
||||
return location;
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(rspStr);
|
||||
String data = jsonObject.getString("data");
|
||||
JSONObject jsonData = JSON.parseObject(data);
|
||||
String region = jsonData.getString("region");
|
||||
String city = jsonData.getString("city");
|
||||
location = region + " " + city;
|
||||
if (location.contains("内网IP")) {
|
||||
location = "内网(" + ip + ")";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.printf(getIpLocation("172.16.0.221"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.lab1024.smartadmin.common.domain.OrderItemDTO;
|
||||
import net.lab1024.smartadmin.common.domain.PageParamDTO;
|
||||
import net.lab1024.smartadmin.common.domain.PageResultDTO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 分页工具类
|
||||
*
|
||||
* @author GHQ
|
||||
* @date 2017-12-23 16:40
|
||||
*/
|
||||
|
||||
public class SmartPageUtil {
|
||||
|
||||
public static <T> PageResultDTO<T> convert2PageResult(IPage<T> page) {
|
||||
PageResultDTO<T> result = new PageResultDTO<>();
|
||||
result.setPageNum(page.getCurrent());
|
||||
result.setPageSize(page.getSize());
|
||||
result.setTotal(Long.valueOf(page.getTotal()));
|
||||
result.setPages(page.getPages());
|
||||
result.setList(page.getRecords());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Page<T> convert2QueryPage(PageParamDTO baseDTO) {
|
||||
Page<T> page = new Page<>();
|
||||
|
||||
List<OrderItemDTO> orders = baseDTO.getOrders();
|
||||
if (orders != null && !orders.isEmpty()) {
|
||||
List<com.baomidou.mybatisplus.core.metadata.OrderItem> orderItemList = orders.stream().map(e -> convertOrderItem(e)).collect(Collectors.toList());
|
||||
page.setOrders(orderItemList);
|
||||
}
|
||||
page.setCurrent(baseDTO.getPageNum());
|
||||
page.setSize(baseDTO.getPageSize());
|
||||
if (null != baseDTO.getSearchCount()) {
|
||||
page.setSearchCount(baseDTO.getSearchCount());
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private static com.baomidou.mybatisplus.core.metadata.OrderItem convertOrderItem(OrderItemDTO orderItemDTO) {
|
||||
if (orderItemDTO.isAsc()) {
|
||||
return com.baomidou.mybatisplus.core.metadata.OrderItem.asc(orderItemDTO.getColumn());
|
||||
} else {
|
||||
return com.baomidou.mybatisplus.core.metadata.OrderItem.desc(orderItemDTO.getColumn());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 PageResultDTO 对象
|
||||
*
|
||||
* @param page
|
||||
* @param sourceList 原list
|
||||
* @param targetClazz 目标类
|
||||
* @return
|
||||
* @author yandanyang
|
||||
* @date 2018年5月16日 下午6:05:28
|
||||
*/
|
||||
public static <T, E> PageResultDTO<T> convert2PageResult(IPage page, List<E> sourceList, Class<T> targetClazz) {
|
||||
PageResultDTO pageResultDTO = setPage(page);
|
||||
List<T> records = SmartBeanUtil.copyList(sourceList, targetClazz);
|
||||
page.setRecords(records);
|
||||
pageResultDTO.setList(records);
|
||||
return pageResultDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 PageResultDTO 对象
|
||||
*
|
||||
* @param page
|
||||
* @param sourceList list
|
||||
* @return
|
||||
* @author yandanyang
|
||||
* @date 2018年5月16日 下午6:05:28
|
||||
*/
|
||||
public static <T, E> PageResultDTO<T> convert2PageResult(IPage page, List<E> sourceList) {
|
||||
PageResultDTO pageResultDTO = setPage(page);
|
||||
page.setRecords(sourceList);
|
||||
pageResultDTO.setList(sourceList);
|
||||
return pageResultDTO;
|
||||
}
|
||||
|
||||
private static PageResultDTO setPage(IPage page) {
|
||||
PageResultDTO pageResultDTO = new PageResultDTO();
|
||||
pageResultDTO.setPageNum(page.getCurrent());
|
||||
pageResultDTO.setPageSize(page.getSize());
|
||||
pageResultDTO.setTotal(Long.valueOf(page.getTotal()));
|
||||
pageResultDTO.setPages(page.getPages());
|
||||
return pageResultDTO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import net.lab1024.smartadmin.module.support.quartz.constant.QuartzConst;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
|
||||
/**
|
||||
* [ ]
|
||||
*
|
||||
* @author yandanyang
|
||||
* @version 1.0
|
||||
* @company 1024lab.net
|
||||
* @copyright (c) 2018 1024lab.netInc. All rights reserved.
|
||||
* @date 2019/4/13 0013 下午 15:16
|
||||
* @since JDK1.8
|
||||
*/
|
||||
public class SmartQuartzUtil {
|
||||
|
||||
public static Long getTaskIdByJobKey(JobKey jobKey) {
|
||||
String name = jobKey.getName();
|
||||
return Long.valueOf(StringUtils.replace(name, QuartzConst.JOB_KEY_PREFIX, ""));
|
||||
}
|
||||
|
||||
public static Integer getTaskIdByTriggerKey(TriggerKey triggerKey) {
|
||||
String name = triggerKey.getName();
|
||||
return Integer.valueOf(StringUtils.replace(name, QuartzConst.TRIGGER_KEY_PREFIX, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取触发器key
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long taskId) {
|
||||
return TriggerKey.triggerKey(QuartzConst.TRIGGER_KEY_PREFIX + taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jobKey
|
||||
*/
|
||||
public static JobKey getJobKey(Long taskId) {
|
||||
return JobKey.jobKey(QuartzConst.JOB_KEY_PREFIX + taskId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import net.lab1024.smartadmin.module.business.login.domain.RequestTokenBO;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
/**
|
||||
* @author yandanyang
|
||||
* @version 1.0
|
||||
* @company 1024lab.net
|
||||
* @copyright (c) 2019 1024lab.netInc. All rights reserved.
|
||||
* @date
|
||||
* @since JDK1.8
|
||||
*/
|
||||
public class SmartRequestTokenUtil {
|
||||
|
||||
private static final String USER_KEY = "smart_admin_user";
|
||||
|
||||
private static ThreadLocal<RequestTokenBO> RequestUserThreadLocal = new ThreadLocal<RequestTokenBO>();
|
||||
|
||||
public static void setUser(HttpServletRequest request, RequestTokenBO requestToken) {
|
||||
request.setAttribute(USER_KEY, requestToken);
|
||||
RequestUserThreadLocal.set(requestToken);
|
||||
}
|
||||
|
||||
public static RequestTokenBO getThreadLocalUser() {
|
||||
return RequestUserThreadLocal.get();
|
||||
}
|
||||
|
||||
public static RequestTokenBO getRequestUser() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes != null) {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||
if (request != null) {
|
||||
return (RequestTokenBO) request.getAttribute(USER_KEY);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Long getRequestUserId() {
|
||||
RequestTokenBO requestUser = getRequestUser();
|
||||
if (null == requestUser) {
|
||||
return null;
|
||||
}
|
||||
return requestUser.getRequestUserId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.*;
|
||||
import javax.mail.util.ByteArrayDataSource;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
public class SmartSendMailUtil {
|
||||
|
||||
/**
|
||||
* 邮箱正则表达式
|
||||
*/
|
||||
static final Pattern pattern = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// 发件人的 邮箱 和 密码(替换为自己的邮箱和密码)
|
||||
// PS: 某些邮箱服务器为了增加邮箱本身密码的安全性,给 SMTP 客户端设置了独立密码(有的邮箱称为“授权码”),
|
||||
// 对于开启了独立密码的邮箱, 这里的邮箱密码必需使用这个独立密码(授权码)。
|
||||
String myEmailAccount = "xxxxx@163.com";
|
||||
String myEmailPassword = "xxxxxx";
|
||||
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
|
||||
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
|
||||
String myEmailSMTPHost = "smtp.163.com";
|
||||
// 收件人邮箱(替换为自己知道的有效邮箱)
|
||||
String[] toMailAccountList = new String[]{"421316927@qq.com"};
|
||||
SmartSendMailUtil.sendMail(myEmailAccount, myEmailPassword, "", toMailAccountList, "", myEmailSMTPHost, "测试发送邮件", "测试发送邮件");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本邮件
|
||||
*
|
||||
* @param sendMail 发件人邮箱
|
||||
* @param sendMailPwd 发件人密码
|
||||
* @param sendMailName 发件人昵称(可选)
|
||||
* @param receiveMail 收件人邮箱
|
||||
* @param receiveMailName 收件人昵称(可选)
|
||||
* @param sendSMTPHost 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
|
||||
* @param title 邮件主题
|
||||
* @param content 邮件正文
|
||||
* @author Administrator
|
||||
* @date 2017年12月13日 下午1:51:38
|
||||
*/
|
||||
public static void sendMail(String sendMail, String sendMailPwd, String sendMailName, String[] receiveMail, String receiveMailName, String sendSMTPHost, String title, String content) {
|
||||
|
||||
Session session = createSession(sendSMTPHost);
|
||||
// 3. 创建一封邮件
|
||||
MimeMessage message;
|
||||
try {
|
||||
message = createMimeMessage(session, sendMail, sendMailName, receiveMail, receiveMailName, title, content);
|
||||
// 4. 根据 Session 获取邮件传输对象
|
||||
Transport transport = session.getTransport();
|
||||
|
||||
// 5. 使用 邮箱账号 和 密码 连接邮件服务器, 这里认证的邮箱必须与 message 中的发件人邮箱一致, 否则报错
|
||||
//
|
||||
// PS_01: 成败的判断关键在此一句, 如果连接服务器失败, 都会在控制台输出相应失败原因的 log,
|
||||
// 仔细查看失败原因, 有些邮箱服务器会返回错误码或查看错误类型的链接, 根据给出的错误
|
||||
// 类型到对应邮件服务器的帮助网站上查看具体失败原因。
|
||||
//
|
||||
// PS_02: 连接失败的原因通常为以下几点, 仔细检查代码:
|
||||
// (1) 邮箱没有开启 SMTP 服务;
|
||||
// (2) 邮箱密码错误, 例如某些邮箱开启了独立密码;
|
||||
// (3) 邮箱服务器要求必须要使用 SSL 安全连接;
|
||||
// (4) 请求过于频繁或其他原因, 被邮件服务器拒绝服务;
|
||||
// (5) 如果以上几点都确定无误, 到邮件服务器网站查找帮助。
|
||||
//
|
||||
// PS_03: 仔细看log, 认真看log, 看懂log, 错误原因都在log已说明。
|
||||
transport.connect(sendMail, sendMailPwd);
|
||||
// 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
// 7. 关闭连接
|
||||
transport.close();
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送带附件的邮件
|
||||
*
|
||||
* @param sendMail 发件人邮箱
|
||||
* @param sendMailPwd 发件人密码
|
||||
* @param sendMailName 发件人昵称(可选)
|
||||
* @param receiveMail 收件人邮箱
|
||||
* @param receiveMailName 收件人昵称(可选)
|
||||
* @param sendSMTPHost 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般(只是一般, 绝非绝对)格式为: smtp.xxx.com
|
||||
* @param title 邮件主题
|
||||
* @param content 邮件正文
|
||||
* @author Administrator
|
||||
* @date 2017年12月13日 下午1:51:38
|
||||
*/
|
||||
public static void sendFileMail(String sendMail, String sendMailPwd, String sendMailName, String[] receiveMail, String receiveMailName, String sendSMTPHost, String title, String content,
|
||||
InputStream is, String fileName, String port) {
|
||||
|
||||
Session session = createSSLSession(sendSMTPHost, port, sendMailName, sendMailPwd);
|
||||
// 3. 创建一封邮件
|
||||
MimeMessage message;
|
||||
try {
|
||||
message = createMimeMessage(session, sendMail, sendMailName, receiveMail, receiveMailName, title, content);
|
||||
// 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
|
||||
MimeMultipart mm = new MimeMultipart();
|
||||
MimeBodyPart text = new MimeBodyPart();
|
||||
text.setContent(content, "text/html;charset=UTF-8");
|
||||
mm.addBodyPart(text);
|
||||
if (null != is && is.available() > 0) {
|
||||
MimeBodyPart attachment = new MimeBodyPart();
|
||||
DataSource source = new ByteArrayDataSource(is, "application/msexcel");
|
||||
// 将附件数据添加到"节点"
|
||||
attachment.setDataHandler(new DataHandler(source));
|
||||
// 设置附件的文件名(需要编码)
|
||||
attachment.setFileName(MimeUtility.encodeText(fileName));
|
||||
// 10. 设置文本和 附件 的关系(合成一个大的混合"节点" / Multipart )
|
||||
// 如果有多个附件,可以创建多个多次添加
|
||||
mm.addBodyPart(attachment);
|
||||
}
|
||||
message.setContent(mm);
|
||||
message.saveChanges();
|
||||
// 4. 根据 Session 获取邮件传输对象
|
||||
Transport transport = session.getTransport("smtp");
|
||||
transport.connect(sendSMTPHost, sendMail, sendMailPwd);
|
||||
// // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
// 7. 关闭连接
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建session
|
||||
*
|
||||
* @author lidoudou
|
||||
* @date 2019/2/16 14:59
|
||||
*/
|
||||
private static Session createSSLSession(String sendSMTPHost, String port, String userName, String pwd) {
|
||||
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
||||
Properties props = new Properties(); // 参数配置
|
||||
|
||||
props.setProperty("mail.smtp.user", userName);
|
||||
props.setProperty("mail.smtp.password", pwd);
|
||||
props.setProperty("mail.smtp.host", sendSMTPHost);
|
||||
props.setProperty("mail.smtp.port", port);
|
||||
props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
props.setProperty("mail.smtp.socketFactory.fallback", "false");
|
||||
props.setProperty("mail.smtp.socketFactory.port", port);
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
// 2. 根据配置创建会话对象, 用于和邮件服务器交互
|
||||
Session session = Session.getDefaultInstance(props, new Authenticator() {
|
||||
//身份认证
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(userName, pwd);
|
||||
}
|
||||
});
|
||||
session.setDebug(true); // 设置为debug模式, 可以查看详细的发送 log
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建session
|
||||
*
|
||||
* @author lidoudou
|
||||
* @date 2019/2/16 14:59
|
||||
*/
|
||||
private static Session createSession(String sendSMTPHost) {
|
||||
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
||||
Properties props = new Properties(); // 参数配置
|
||||
props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
||||
props.setProperty("mail.smtp.host", sendSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
|
||||
props.setProperty("mail.smtp.auth", "true"); // 需要请求认证
|
||||
// PS: 某些邮箱服务器要求 SMTP 连接需要使用 SSL 安全认证 (为了提高安全性, 邮箱支持SSL连接, 也可以自己开启),
|
||||
// 如果无法连接邮件服务器, 仔细查看控制台打印的 log, 如果有有类似 “连接失败, 要求 SSL 安全连接” 等错误,
|
||||
// 打开下面 /* ... */ 之间的注释代码, 开启 SSL 安全连接。
|
||||
/*
|
||||
* // SMTP 服务器的端口 (非 SSL 连接的端口一般默认为 25, 可以不添加, 如果开启了 SSL 连接, // 需要改为对应邮箱的 SMTP 服务器的端口,
|
||||
* 具体可查看对应邮箱服务的帮助, // QQ邮箱的SMTP(SLL)端口为465或587, 其他邮箱自行去查看) final String smtpPort = "465";
|
||||
* props.setProperty("mail.smtp.port", smtpPort);
|
||||
* props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
* props.setProperty("mail.smtp.socketFactory.fallback", "false");
|
||||
* props.setProperty("mail.smtp.socketFactory.port", smtpPort);
|
||||
*/
|
||||
// 2. 根据配置创建会话对象, 用于和邮件服务器交互
|
||||
Session session = Session.getInstance(props);
|
||||
session.setDebug(true); // 设置为debug模式, 可以查看详细的发送 log
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一封只包含文本的简单邮件
|
||||
*
|
||||
* @param session 和服务器交互的会话
|
||||
* @param sendMail 发件人邮箱
|
||||
* @param sendMailName 发件人昵称
|
||||
* @param receiveMail 收件人邮箱
|
||||
* @param receiveMailName 收件人昵称
|
||||
* @param title 邮件主题
|
||||
* @param content 邮件正文
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @author Administrator
|
||||
* @date 2017年12月13日 下午1:55:45
|
||||
*/
|
||||
public static MimeMessage createMimeMessage(Session session, String sendMail, String sendMailName, String[] receiveMail, String receiveMailName, String title, String content) throws Exception {
|
||||
// 1. 创建一封邮件
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
// 2. From: 发件人(昵称有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改昵称)
|
||||
message.setFrom(new InternetAddress(sendMail, sendMailName, "UTF-8"));
|
||||
// 3. To: 收件人(可以增加多个收件人、抄送、密送)
|
||||
List<InternetAddress> to = new LinkedList<>();
|
||||
for (String s : receiveMail) {
|
||||
if (pattern.matcher(s).matches()) {
|
||||
to.add(new InternetAddress(s));
|
||||
}
|
||||
}
|
||||
//Address[] addresses = new Address[]{new InternetAddress(receiveMail),new InternetAddress(receiveMail)};
|
||||
message.addRecipients(MimeMessage.RecipientType.TO, to.toArray((new InternetAddress[to.size()])));
|
||||
// 4. Subject: 邮件主题(标题有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改标题)
|
||||
message.setSubject(title, "UTF-8");
|
||||
// 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
|
||||
message.setContent(content, "text/html;charset=UTF-8");
|
||||
// 6. 设置发件时间
|
||||
message.setSentDate(new Date());
|
||||
// 7. 保存设置
|
||||
message.saveChanges();
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 字符串操作类,包括分割,转换,大写首字母
|
||||
*
|
||||
* @author jiaozi
|
||||
*/
|
||||
public class SmartStringUtil extends StringUtils {
|
||||
|
||||
// ===============split =======================
|
||||
|
||||
public static Set<String> splitConvertToSet(String str, String split) {
|
||||
if (isEmpty(str)) {
|
||||
return new HashSet<String>();
|
||||
}
|
||||
String[] splitArr = str.split(split);
|
||||
HashSet<String> set = new HashSet<String>(splitArr.length);
|
||||
for (String string : splitArr) {
|
||||
set.add(string);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static List<String> splitConvertToList(String str, String split) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
String[] splitArr = str.split(split);
|
||||
ArrayList<String> list = new ArrayList<String>(splitArr.length);
|
||||
for (String string : splitArr) {
|
||||
list.add(string);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// ===============split Integer=======================
|
||||
|
||||
public static List<Integer> splitConverToIntList(String str, String split, int defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<Integer>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
List<Integer> list = new ArrayList<Integer>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
int parseInt = Integer.parseInt(strArr[i]);
|
||||
list.add(parseInt);
|
||||
} catch (NumberFormatException e) {
|
||||
list.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Set<Integer> splitConverToIntSet(String str, String split, int defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new HashSet<Integer>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
HashSet<Integer> set = new HashSet<Integer>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
int parseInt = Integer.parseInt(strArr[i]);
|
||||
set.add(parseInt);
|
||||
} catch (NumberFormatException e) {
|
||||
set.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static Set<Integer> splitConverToIntSet(String str, String split) {
|
||||
return splitConverToIntSet(str, split, 0);
|
||||
}
|
||||
|
||||
public static List<Integer> splitConverToIntList(String str, String split) {
|
||||
return splitConverToIntList(str, split, 0);
|
||||
}
|
||||
|
||||
public static int[] splitConvertToIntArray(String str, String split, int defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new int[0];
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
int[] result = new int[strArr.length];
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
result[i] = Integer.parseInt(strArr[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
result[i] = defaultVal;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int[] splitConvertToIntArray(String str, String split) {
|
||||
return splitConvertToIntArray(str, split, 0);
|
||||
}
|
||||
|
||||
// ===============split 2 Long=======================
|
||||
|
||||
public static List<Long> splitConverToLongList(String str, String split, long defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<Long>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
List<Long> list = new ArrayList<Long>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
long parseLong = Long.parseLong(strArr[i]);
|
||||
list.add(parseLong);
|
||||
} catch (NumberFormatException e) {
|
||||
list.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Long> splitConverToLongList(String str, String split) {
|
||||
return splitConverToLongList(str, split, 0L);
|
||||
}
|
||||
|
||||
public static long[] splitConvertToLongArray(String str, String split, long defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new long[0];
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
long[] result = new long[strArr.length];
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
result[i] = Long.parseLong(strArr[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
result[i] = defaultVal;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long[] splitConvertToLongArray(String str, String split) {
|
||||
return splitConvertToLongArray(str, split, 0L);
|
||||
}
|
||||
|
||||
// ===============split convert byte=======================
|
||||
|
||||
public static List<Byte> splitConverToByteList(String str, String split, byte defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<Byte>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
List<Byte> list = new ArrayList<Byte>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
byte parseByte = Byte.parseByte(strArr[i]);
|
||||
list.add(parseByte);
|
||||
} catch (NumberFormatException e) {
|
||||
list.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Byte> splitConverToByteList(String str, String split) {
|
||||
return splitConverToByteList(str, split, (byte) 0);
|
||||
}
|
||||
|
||||
public static byte[] splitConvertToByteArray(String str, String split, byte defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new byte[0];
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
byte[] result = new byte[strArr.length];
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
result[i] = Byte.parseByte(strArr[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
result[i] = defaultVal;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] splitConvertToByteArray(String str, String split) {
|
||||
return splitConvertToByteArray(str, split, (byte) 0);
|
||||
}
|
||||
|
||||
// ===============split convert double=======================
|
||||
|
||||
public static List<Double> splitConverToDoubleList(String str, String split, double defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<Double>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
List<Double> list = new ArrayList<Double>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
double parseByte = Double.parseDouble(strArr[i]);
|
||||
list.add(parseByte);
|
||||
} catch (NumberFormatException e) {
|
||||
list.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Double> splitConverToDoubleList(String str, String split) {
|
||||
return splitConverToDoubleList(str, split, 0);
|
||||
}
|
||||
|
||||
public static double[] splitConvertToDoubleArray(String str, String split, double defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new double[0];
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
double[] result = new double[strArr.length];
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
result[i] = Double.parseDouble(strArr[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
result[i] = defaultVal;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double[] splitConvertToDoubleArray(String str, String split) {
|
||||
return splitConvertToDoubleArray(str, split, 0);
|
||||
}
|
||||
|
||||
// ===============solit convert float=======================
|
||||
|
||||
public static List<Float> splitConverToFloatList(String str, String split, float defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new ArrayList<Float>();
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
List<Float> list = new ArrayList<Float>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
float parseByte = Float.parseFloat(strArr[i]);
|
||||
list.add(parseByte);
|
||||
} catch (NumberFormatException e) {
|
||||
list.add(defaultVal);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Float> splitConverToFloatList(String str, String split) {
|
||||
return splitConverToFloatList(str, split, 0f);
|
||||
}
|
||||
|
||||
public static float[] splitConvertToFloatArray(String str, String split, float defaultVal) {
|
||||
if (isEmpty(str)) {
|
||||
return new float[0];
|
||||
}
|
||||
String[] strArr = str.split(split);
|
||||
float[] result = new float[strArr.length];
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
try {
|
||||
result[i] = Float.parseFloat(strArr[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
result[i] = defaultVal;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float[] splitConvertToFloatArray(String str, String split) {
|
||||
return splitConvertToFloatArray(str, split, 0f);
|
||||
}
|
||||
|
||||
// ===============upperCase=======================
|
||||
|
||||
/**
|
||||
* 将首字母大写
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String upperCaseFirstChar(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
char firstChar = str.charAt(0);
|
||||
if (Character.isUpperCase(firstChar)) {
|
||||
return str;
|
||||
}
|
||||
char[] values = str.toCharArray();
|
||||
values[0] = Character.toUpperCase(firstChar);
|
||||
return new String(values);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 拥有自己的thread facotry是为了jstack时候能看到是哪个线程
|
||||
*
|
||||
* @author jiaozi
|
||||
*/
|
||||
public class SmartThreadFactory implements ThreadFactory {
|
||||
|
||||
public static SmartThreadFactory create(String namePrefix) {
|
||||
return new SmartThreadFactory(namePrefix);
|
||||
}
|
||||
|
||||
private final AtomicInteger poolNumber = new AtomicInteger(1);
|
||||
|
||||
private final ThreadGroup group;
|
||||
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
|
||||
private final String namePrefix;
|
||||
|
||||
private SmartThreadFactory(String namePrefix) {
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
|
||||
this.namePrefix = namePrefix + " pool " + poolNumber.getAndIncrement() + "-thread-";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
|
||||
if (t.isDaemon()) {
|
||||
t.setDaemon(false);
|
||||
}
|
||||
|
||||
if (t.getPriority() != Thread.NORM_PRIORITY) {
|
||||
t.setPriority(Thread.NORM_PRIORITY);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package net.lab1024.smartadmin.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
/**
|
||||
* 验证工具类
|
||||
*
|
||||
* @author listen
|
||||
* @date 2017/11/06 10:54
|
||||
*/
|
||||
public class SmartVerificationUtil {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 手机号码验证规则
|
||||
*/
|
||||
public static final String PHONE_REGEXP = "^1[0-9]{10}";
|
||||
|
||||
/**
|
||||
* 固定号码验证规则
|
||||
*/
|
||||
public static final String FIXED_PHONE_REGEXP = "^0\\d{2,3}-[1-9]\\d{6,7}$";
|
||||
|
||||
/**
|
||||
* 密码正则校验
|
||||
*/
|
||||
public static final String PWD_REGEXP = "^[A-Za-z0-9.]{6,15}$";
|
||||
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
public static final String CAR_NUMBER =
|
||||
"([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}(([A-HJ-Z]{1}[A-HJ-NP-Z0-9]{5})|([A-HJ-Z]{1}(([DF]{1}[A-HJ-NP-Z0-9]{1}[0-9]{4})|([0-9]{5}[DF]{1})))|" + "([A-HJ-Z" + "]{1}[A-D0-9]{1}[0-9]{3}警)))|" +
|
||||
"([0-9]{6}使)|((([沪粤川云桂鄂陕蒙藏黑辽渝]{1}A)|鲁B|闽D|蒙E|蒙H)[0-9]{4}领)|(WJ[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼·•]{1}[0-9]{4}[TDSHBXJ0-9]{1})|" + "([VKHBSLJNGCE]{1}[A-DJ-PR" + "-TVY]{1}[0-9]{5})";
|
||||
|
||||
/**
|
||||
* 日期年月日校验 yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public static final String DATE_TIME = "^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9" +
|
||||
"]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))\\s+([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$";
|
||||
|
||||
/**
|
||||
* 日期校验 yyyy-MM-dd
|
||||
*/
|
||||
public static final String DATE = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))"
|
||||
+ "|(02-(0[1-9]|[1][0-9]|2[0-8])))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)" + "([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9"
|
||||
+ "][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|(" + "(([0-9]{2})(0[48]|[2468][048]|[13579][26])|(" + "(0[48" + "]|[2468][048]|[3579][26])00))-02-29)";
|
||||
|
||||
/**
|
||||
* 年月校验 例: 2019-10
|
||||
*/
|
||||
public static final String YEAR_MONTH = "^\\d{4}-((0([1-9]))|(1(0|1|2)))$";
|
||||
|
||||
|
||||
/**
|
||||
* 时间区间验证 10:23-19:00
|
||||
*/
|
||||
public static final String TIME_SECTION= "^(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])-(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])$";
|
||||
|
||||
/**
|
||||
* 时间验证 10:23
|
||||
*/
|
||||
public static final String TIME = "^(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])$";
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
public static final String ID_CARD = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
|
||||
|
||||
/**
|
||||
* URL
|
||||
*/
|
||||
public static final String URL = "[a-zA-z]+://[^\\s]*";
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
public static final String EMAIL = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
|
||||
|
||||
/**
|
||||
* 整数
|
||||
*/
|
||||
public static final String INTEGER = "^-?[1-9]\\d*$";
|
||||
|
||||
/**
|
||||
* 小数
|
||||
*/
|
||||
public static final String DOUBLE = "^-?[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean matches = Pattern.matches(INTEGER, "1");
|
||||
System.out.println(matches);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user