style: 应用 Spotless 代码格式化
- 对所有 Java 源文件应用统一的代码格式化 - 统一缩进为 4 个空格 - 清理尾随空白字符和文件末尾换行 - 优化导入语句组织 - 总计格式化 654 个 Java 文件 有问题可以回滚或者找我聊
This commit is contained in:
@@ -21,7 +21,6 @@ public @interface DataScope {
|
||||
*/
|
||||
String userAlias() default "";
|
||||
|
||||
|
||||
/**
|
||||
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@ss获取,多个权限用逗号分隔开来
|
||||
*/
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.starry.common.annotation;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
|
||||
/**
|
||||
* 枚举参数校验注解
|
||||
*
|
||||
@@ -40,4 +40,4 @@ public @interface EnumValue {
|
||||
@interface List {
|
||||
EnumValue[] value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,4 @@ public class EnumValueValidator implements ConstraintValidator<EnumValue, Object
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.starry.common.annotation;
|
||||
|
||||
import com.starry.common.enums.BusinessType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 自定义操作日志记录注解
|
||||
* @author admin 自定义操作日志记录注解
|
||||
* @since 2022/7/22
|
||||
*/
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD}) // 注解放置的目标位置,PARAMETER: 可用在参数上 METHOD:可用在方法级别上
|
||||
@Retention(RetentionPolicy.RUNTIME) // 指明修饰的注解的生存周期 RUNTIME:运行级别保留
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD}) // 注解放置的目标位置,PARAMETER: 可用在参数上 METHOD:可用在方法级别上
|
||||
@Retention(RetentionPolicy.RUNTIME) // 指明修饰的注解的生存周期 RUNTIME:运行级别保留
|
||||
@Documented
|
||||
public @interface Log {
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ package com.starry.common.config;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
|
||||
/**
|
||||
* Redis使用FastJson序列化
|
||||
|
||||
@@ -7,8 +7,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* redis 配置
|
||||
* @author admin redis 配置
|
||||
* @since 2022/10/18
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.starry.common.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
@@ -10,13 +12,8 @@ import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* swagger配置
|
||||
* @author admin swagger配置
|
||||
* @since 2021/9/1
|
||||
*/
|
||||
@Configuration
|
||||
@@ -26,19 +23,12 @@ public class Swagger2Config {
|
||||
@Bean(value = "defaultApi2")
|
||||
public Docket defaultApi2() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(new ApiInfoBuilder()
|
||||
.title("接口文档")
|
||||
.description("# 接口文档")
|
||||
.termsOfServiceUrl("http://www.xx.com/")
|
||||
.contact("277769738@qq.com")
|
||||
.version("1.0")
|
||||
.build())
|
||||
.apiInfo(new ApiInfoBuilder().title("接口文档").description("# 接口文档")
|
||||
.termsOfServiceUrl("http://www.xx.com/").contact("277769738@qq.com").version("1.0").build())
|
||||
// 分组名称
|
||||
.groupName("2.X版本")
|
||||
.select()
|
||||
.groupName("2.X版本").select()
|
||||
// 这里指定Controller扫描包路径
|
||||
.apis(RequestHandlerSelectors.basePackage("com.starry.admin.modules"))
|
||||
.paths(PathSelectors.any())
|
||||
.apis(RequestHandlerSelectors.basePackage("com.starry.admin.modules")).paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package com.starry.common.config;
|
||||
|
||||
|
||||
import com.starry.common.utils.ThreadsUtils;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 线程池配置
|
||||
* @author admin 线程池配置
|
||||
* @since 2022/7/25
|
||||
*/
|
||||
@Configuration
|
||||
@@ -53,7 +50,8 @@ public class ThreadPoolConfig {
|
||||
*/
|
||||
@Bean(name = "scheduledExecutorService")
|
||||
protected ScheduledExecutorService scheduledExecutorService() {
|
||||
return new ScheduledThreadPoolExecutor(corePoolSize, new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||
return new ScheduledThreadPoolExecutor(corePoolSize,
|
||||
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()) {
|
||||
@Override
|
||||
protected void afterExecute(Runnable r, Throwable t) {
|
||||
@@ -63,5 +61,4 @@ public class ThreadPoolConfig {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package com.starry.common.config.typehandler;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 存储到数据库, 将LONG数组转换成字符串;
|
||||
* 从数据库获取数据, 将字符串转为LONG数组.
|
||||
* 存储到数据库, 将LONG数组转换成字符串; 从数据库获取数据, 将字符串转为LONG数组.
|
||||
*/
|
||||
@MappedTypes({Long[].class})
|
||||
@MappedJdbcTypes({JdbcType.VARCHAR})
|
||||
@@ -22,26 +20,23 @@ public class ArrayLongTypeHandler extends BaseTypeHandler<Long[]> {
|
||||
private static final Long[] l = new Long[]{};
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i,
|
||||
Long[] parameter, JdbcType jdbcType) throws SQLException {
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, Long[] parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, JSONUtil.toJsonStr(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long[] getNullableResult(ResultSet rs, String columnName)
|
||||
throws SQLException {
|
||||
public Long[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return JSONUtil.parseArray(rs.getString(columnName)).toArray(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long[] getNullableResult(ResultSet rs, int columnIndex)
|
||||
throws SQLException {
|
||||
public Long[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return JSONUtil.parseArray(rs.getString(columnIndex)).toArray(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long[] getNullableResult(CallableStatement cs, int columnIndex)
|
||||
throws SQLException {
|
||||
public Long[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return JSONUtil.parseArray(cs.getString(columnIndex)).toArray(l);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package com.starry.common.config.typehandler;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 存储到数据库, 将String数组转换成字符串;
|
||||
* 从数据库获取数据, 将字符串转为LONG数组.
|
||||
* 存储到数据库, 将String数组转换成字符串; 从数据库获取数据, 将字符串转为LONG数组.
|
||||
*/
|
||||
@MappedTypes({String[].class})
|
||||
@MappedJdbcTypes({JdbcType.VARCHAR})
|
||||
@@ -22,26 +20,23 @@ public class ArrayStringTypeHandler extends BaseTypeHandler<String[]> {
|
||||
private static final String[] l = new String[]{};
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i,
|
||||
String[] parameter, JdbcType jdbcType) throws SQLException {
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, JSONUtil.toJsonStr(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, String columnName)
|
||||
throws SQLException {
|
||||
public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return JSONUtil.parseArray(rs.getString(columnName)).toArray(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(ResultSet rs, int columnIndex)
|
||||
throws SQLException {
|
||||
public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return JSONUtil.parseArray(rs.getString(columnIndex)).toArray(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getNullableResult(CallableStatement cs, int columnIndex)
|
||||
throws SQLException {
|
||||
public String[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return JSONUtil.parseArray(cs.getString(columnIndex)).toArray(l);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,34 +2,31 @@ package com.starry.common.config.typehandler;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 存储到数据库, 将JSON对象转换成字符串;
|
||||
* 从数据库获取数据, 将字符串转为JSON对象.
|
||||
* 存储到数据库, 将JSON对象转换成字符串; 从数据库获取数据, 将字符串转为JSON对象.
|
||||
*/
|
||||
@MappedTypes({JSONObject.class})
|
||||
@MappedJdbcTypes({JdbcType.VARCHAR})
|
||||
public class JsonTypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter,
|
||||
JdbcType jdbcType) throws SQLException {
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
|
||||
ps.setString(i, JSONUtil.toJsonStr(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, String columnName)
|
||||
throws SQLException {
|
||||
public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
|
||||
return JSONUtil.parseObj(rs.getString(columnName)).toBean(JSONObject.class);
|
||||
}
|
||||
@@ -41,8 +38,7 @@ public class JsonTypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(CallableStatement cs, int columnIndex)
|
||||
throws SQLException {
|
||||
public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
|
||||
return JSONUtil.parseObj(cs.getString(columnIndex)).toBean(JSONObject.class);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.starry.common.constant;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 通用常量信息
|
||||
* @author admin 通用常量信息
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
@@ -66,7 +65,4 @@ public class Constants {
|
||||
public static final String LOGIN_USER_KEY_MINI = "login_user_key_mini";
|
||||
public static final String LOGIN_USER_KEY_COSER = "login_user_key_coser";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.starry.common.constant;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 权限相关常量
|
||||
* @author admin 权限相关常量
|
||||
*/
|
||||
public class SecurityConstants {
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ package com.starry.common.constant;
|
||||
public class UserConstants {
|
||||
|
||||
/**
|
||||
* 校验返回结果码 0:唯一 1:不唯一
|
||||
* 校验返回结果码 0:唯一 1:不唯一
|
||||
*/
|
||||
public final static String UNIQUE = "0";
|
||||
public final static String NOT_UNIQUE = "1";
|
||||
|
||||
@@ -4,13 +4,11 @@ import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.starry.common.constant.SecurityConstants;
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 获取当前线程变量中的 租户id 部门id 用户id、用户名称、Token等信息
|
||||
* @author admin 获取当前线程变量中的 租户id 部门id 用户id、用户名称、Token等信息
|
||||
* @since 2023/3/6
|
||||
*/
|
||||
public class CustomSecurityContextHolder {
|
||||
@@ -27,7 +25,6 @@ public class CustomSecurityContextHolder {
|
||||
return Convert.toStr(map.getOrDefault(key, StringUtils.EMPTY));
|
||||
}
|
||||
|
||||
|
||||
public static <T> T get(String key, Class<T> clazz) {
|
||||
Map<String, Object> map = getLocalMap();
|
||||
return StringUtils.cast(map.getOrDefault(key, null));
|
||||
@@ -46,7 +43,6 @@ public class CustomSecurityContextHolder {
|
||||
THREAD_LOCAL.set(threadLocalMap);
|
||||
}
|
||||
|
||||
|
||||
public static String getTenantId() {
|
||||
return Convert.toStr(get(SecurityConstants.DETAILS_TENANT_ID), "9999");
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package com.starry.common.controller;
|
||||
|
||||
|
||||
import com.starry.common.domain.Captcha;
|
||||
import com.starry.common.redis.CaptchaService;
|
||||
import com.starry.common.result.R;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 验证码前端控制器
|
||||
* @author admin 验证码前端控制器
|
||||
* @since 2022/7/7
|
||||
*/
|
||||
@RestController
|
||||
|
||||
@@ -4,20 +4,18 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 基类
|
||||
* @author admin 基类
|
||||
* @since 2022/7/14
|
||||
*/
|
||||
@Getter
|
||||
|
||||
@@ -3,16 +3,14 @@ package com.starry.common.domain;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 分页基类
|
||||
* @author admin 分页基类
|
||||
* @since 2021/9/2
|
||||
*/
|
||||
@Data
|
||||
@@ -64,4 +62,3 @@ public class BasePageEntity implements Serializable {
|
||||
private String endTime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.starry.common.domain;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 验证码拼图类
|
||||
* @author admin 验证码拼图类
|
||||
*/
|
||||
@Data
|
||||
public class Captcha {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.starry.common.enums;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 业务操作类型
|
||||
* @author admin 业务操作类型
|
||||
* @since 2022/7/22
|
||||
*/
|
||||
public enum BusinessType {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.starry.common.filter;
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Repeatable 过滤器
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.starry.common.filter;
|
||||
|
||||
|
||||
import com.starry.common.utils.http.HttpHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* 构建可重复读取inputStream的request
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.starry.common.filter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 防止XSS攻击的过滤器
|
||||
@@ -76,4 +75,4 @@ public class XssFilter implements Filter {
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,16 @@ package com.starry.common.filter;
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
import com.starry.common.utils.html.EscapeUtil;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* XSS过滤处理
|
||||
@@ -87,4 +86,4 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
||||
String header = super.getHeader(HttpHeaders.CONTENT_TYPE);
|
||||
return MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.starry.common.constant.CacheConstants;
|
||||
import com.starry.common.domain.Captcha;
|
||||
import com.starry.common.utils.CaptchaUtils;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 验证码服务
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.starry.common.redis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author rieds 工具类
|
||||
* @since 2022/8/26
|
||||
@@ -22,7 +21,8 @@ public class RedisCache {
|
||||
/**
|
||||
* 获得缓存的基本对象。
|
||||
*
|
||||
* @param key 缓存键值
|
||||
* @param key
|
||||
* 缓存键值
|
||||
* @return 缓存键值对应的数据
|
||||
*/
|
||||
public <T> T getCacheObject(final String key) {
|
||||
@@ -38,8 +38,10 @@ public class RedisCache {
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
* @param value 缓存的值
|
||||
* @param key
|
||||
* 缓存的键值
|
||||
* @param value
|
||||
* 缓存的值
|
||||
*/
|
||||
public <T> void setCacheObject(final String key, final T value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
@@ -48,10 +50,14 @@ public class RedisCache {
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
* @param value 缓存的值
|
||||
* @param timeout 过期时间
|
||||
* @param timeUnit 时间颗粒度
|
||||
* @param key
|
||||
* 缓存的键值
|
||||
* @param value
|
||||
* 缓存的值
|
||||
* @param timeout
|
||||
* 过期时间
|
||||
* @param timeUnit
|
||||
* 时间颗粒度
|
||||
*/
|
||||
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
||||
@@ -69,7 +75,8 @@ public class RedisCache {
|
||||
/**
|
||||
* 获得缓存的基本对象列表
|
||||
*
|
||||
* @param pattern 字符串前缀
|
||||
* @param pattern
|
||||
* 字符串前缀
|
||||
* @return 对象列表
|
||||
*/
|
||||
public Collection<String> keys(final String pattern) {
|
||||
@@ -79,7 +86,8 @@ public class RedisCache {
|
||||
/**
|
||||
* 删除集合对象
|
||||
*
|
||||
* @param collection 多个对象
|
||||
* @param collection
|
||||
* 多个对象
|
||||
* @return
|
||||
*/
|
||||
public long deleteObject(final Collection collection) {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.starry.common.result;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
@@ -49,7 +47,8 @@ public class R implements Serializable {
|
||||
Page<?> page = (Page<?>) data;
|
||||
this.total = page.getTotal();
|
||||
this.data = page.getRecords();
|
||||
this.pageInfo = new PageInfo((int) page.getCurrent(), (int) page.getSize(), page.getTotal(), page.getPages());
|
||||
this.pageInfo = new PageInfo((int) page.getCurrent(), (int) page.getSize(), page.getTotal(),
|
||||
page.getPages());
|
||||
} else {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.starry.common.result;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 返回码枚举
|
||||
* @author admin 返回码枚举
|
||||
*/
|
||||
public enum ResultCodeEnum implements IBaseEnum {
|
||||
|
||||
SUCCESS(200, "操作成功"),
|
||||
FAILED(500, "操作失败"),
|
||||
VALIDATE_FAILED(404, "参数检验失败"),
|
||||
UNAUTHORIZED(401, "无效的会话,或者会话已过期,请重新登录。"),
|
||||
FORBIDDEN(403, "没有相关权限"),
|
||||
TENANT_NOT_FOUND(403, "租户不存在");
|
||||
SUCCESS(200, "操作成功"), FAILED(500, "操作失败"), VALIDATE_FAILED(404, "参数检验失败"), UNAUTHORIZED(401,
|
||||
"无效的会话,或者会话已过期,请重新登录。"), FORBIDDEN(403, "没有相关权限"), TENANT_NOT_FOUND(403, "租户不存在");
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.starry.common.sensitive;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -6,16 +6,15 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* <p>
|
||||
* 脱敏序列化
|
||||
* <p>
|
||||
* 脱敏序列化
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -25,30 +24,31 @@ public class SensitiveSerialize extends JsonSerializer<String> implements Contex
|
||||
|
||||
@Override
|
||||
public void serialize(final String originStr, final JsonGenerator jsonGenerator,
|
||||
final SerializerProvider serializerProvider) throws IOException {
|
||||
final SerializerProvider serializerProvider) throws IOException {
|
||||
switch (type) {
|
||||
case CHINESE_NAME:
|
||||
case CHINESE_NAME :
|
||||
jsonGenerator.writeString(SensitiveUtils.chineseName(originStr));
|
||||
break;
|
||||
case MOBILE_PHONE:
|
||||
case MOBILE_PHONE :
|
||||
jsonGenerator.writeString(SensitiveUtils.mobilePhone(originStr));
|
||||
break;
|
||||
case EMAIL:
|
||||
case EMAIL :
|
||||
jsonGenerator.writeString(SensitiveUtils.email(originStr));
|
||||
break;
|
||||
case PASSWORD:
|
||||
case PASSWORD :
|
||||
jsonGenerator.writeString(SensitiveUtils.password(originStr));
|
||||
break;
|
||||
case KEY:
|
||||
case KEY :
|
||||
jsonGenerator.writeString(SensitiveUtils.key(originStr));
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
throw new IllegalArgumentException("未定义的敏感信息枚举类" + type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonSerializer<?> createContextual(final SerializerProvider serializerProvider, final BeanProperty beanProperty) throws JsonMappingException {
|
||||
public JsonSerializer<?> createContextual(final SerializerProvider serializerProvider,
|
||||
final BeanProperty beanProperty) throws JsonMappingException {
|
||||
if (beanProperty != null) {
|
||||
if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) {
|
||||
Sensitive sensitive = beanProperty.getAnnotation(Sensitive.class);
|
||||
|
||||
@@ -32,10 +32,14 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 对字符串进行脱敏操作
|
||||
*
|
||||
* @param originStr 原始字符串
|
||||
* @param prefixNoMaskLen 左侧需要保留几位明文字段
|
||||
* @param suffixNoMaskLen 右侧需要保留几位明文字段
|
||||
* @param maskStr 用于遮罩的字符串, 如'*'
|
||||
* @param originStr
|
||||
* 原始字符串
|
||||
* @param prefixNoMaskLen
|
||||
* 左侧需要保留几位明文字段
|
||||
* @param suffixNoMaskLen
|
||||
* 右侧需要保留几位明文字段
|
||||
* @param maskStr
|
||||
* 用于遮罩的字符串, 如'*'
|
||||
* @return 脱敏后结果
|
||||
*/
|
||||
public static String process(String originStr, int prefixNoMaskLen, int suffixNoMaskLen, String maskStr) {
|
||||
@@ -61,7 +65,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 中文姓名只显示最后一个汉字
|
||||
*
|
||||
* @param fullName 姓名
|
||||
* @param fullName
|
||||
* 姓名
|
||||
* @return
|
||||
*/
|
||||
public static String chineseName(String fullName) {
|
||||
@@ -74,7 +79,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 手机号码前三位,后四位,如186****2356
|
||||
*
|
||||
* @param num 手机号码
|
||||
* @param num
|
||||
* 手机号码
|
||||
* @return
|
||||
*/
|
||||
public static String mobilePhone(String num) {
|
||||
@@ -84,7 +90,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 地址只显示到地区
|
||||
*
|
||||
* @param address 地址
|
||||
* @param address
|
||||
* 地址
|
||||
* @return
|
||||
*/
|
||||
public static String address(String address) {
|
||||
@@ -94,7 +101,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 电子邮箱 仅显示第一个字母,@后面的地址显示,比如:r**@qq.com
|
||||
*
|
||||
* @param email 电子邮箱
|
||||
* @param email
|
||||
* 电子邮箱
|
||||
* @return
|
||||
*/
|
||||
public static String email(String email) {
|
||||
@@ -113,7 +121,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 密码的全部字符,如:******
|
||||
*
|
||||
* @param password 密码
|
||||
* @param password
|
||||
* 密码
|
||||
* @return
|
||||
*/
|
||||
public static String password(String password) {
|
||||
@@ -126,7 +135,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 密钥除了最后三位,全部,比如:***klo
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param key
|
||||
* 密钥
|
||||
* @return 结果
|
||||
*/
|
||||
public static String key(String key) {
|
||||
@@ -152,4 +162,4 @@ public class SensitiveUtils {
|
||||
String s = mobilePhone("18653653621");
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的加法运算。
|
||||
*
|
||||
* @param v1 被加数
|
||||
* @param v2 加数
|
||||
* @param v1
|
||||
* 被加数
|
||||
* @param v2
|
||||
* 加数
|
||||
* @return 两个参数的和
|
||||
*/
|
||||
public static double add(double v1, double v2) {
|
||||
@@ -37,8 +39,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的减法运算。
|
||||
*
|
||||
* @param v1 被减数
|
||||
* @param v2 减数
|
||||
* @param v1
|
||||
* 被减数
|
||||
* @param v2
|
||||
* 减数
|
||||
* @return 两个参数的差
|
||||
*/
|
||||
public static double sub(double v1, double v2) {
|
||||
@@ -50,8 +54,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的乘法运算。
|
||||
*
|
||||
* @param v1 被乘数
|
||||
* @param v2 乘数
|
||||
* @param v1
|
||||
* 被乘数
|
||||
* @param v2
|
||||
* 乘数
|
||||
* @return 两个参数的积
|
||||
*/
|
||||
public static double mul(double v1, double v2) {
|
||||
@@ -61,11 +67,12 @@ public class Arith {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
|
||||
* 小数点以后10位,以后的数字四舍五入。
|
||||
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后10位,以后的数字四舍五入。
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
* @param v1
|
||||
* 被除数
|
||||
* @param v2
|
||||
* 除数
|
||||
* @return 两个参数的商
|
||||
*/
|
||||
public static double div(double v1, double v2) {
|
||||
@@ -73,18 +80,19 @@ public class Arith {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
|
||||
* 定精度,以后的数字四舍五入。
|
||||
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
* @param scale 表示表示需要精确到小数点以后几位。
|
||||
* @param v1
|
||||
* 被除数
|
||||
* @param v2
|
||||
* 除数
|
||||
* @param scale
|
||||
* 表示表示需要精确到小数点以后几位。
|
||||
* @return 两个参数的商
|
||||
*/
|
||||
public static double div(double v1, double v2, int scale) {
|
||||
if (scale < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"The scale must be a positive integer or zero");
|
||||
throw new IllegalArgumentException("The scale must be a positive integer or zero");
|
||||
}
|
||||
BigDecimal b1 = new BigDecimal(Double.toString(v1));
|
||||
BigDecimal b2 = new BigDecimal(Double.toString(v2));
|
||||
@@ -97,14 +105,15 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的小数位四舍五入处理。
|
||||
*
|
||||
* @param v 需要四舍五入的数字
|
||||
* @param scale 小数点后保留几位
|
||||
* @param v
|
||||
* 需要四舍五入的数字
|
||||
* @param scale
|
||||
* 小数点后保留几位
|
||||
* @return 四舍五入后的结果
|
||||
*/
|
||||
public static double round(double v, int scale) {
|
||||
if (scale < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"The scale must be a positive integer or zero");
|
||||
throw new IllegalArgumentException("The scale must be a positive integer or zero");
|
||||
}
|
||||
BigDecimal b = new BigDecimal(Double.toString(v));
|
||||
BigDecimal one = BigDecimal.ONE;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import com.starry.common.domain.Captcha;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -14,6 +10,8 @@ import java.net.URL;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
|
||||
/**
|
||||
* @author 拼图验证码工具类
|
||||
@@ -110,7 +108,8 @@ public class CaptchaUtils {
|
||||
/**
|
||||
* 抠图,并生成阻塞块
|
||||
**/
|
||||
public static void cutByTemplate(BufferedImage canvasImage, BufferedImage blockImage, int blockWidth, int blockHeight, int blockRadius, int blockX, int blockY) {
|
||||
public static void cutByTemplate(BufferedImage canvasImage, BufferedImage blockImage, int blockWidth,
|
||||
int blockHeight, int blockRadius, int blockX, int blockY) {
|
||||
BufferedImage waterImage = new BufferedImage(blockWidth, blockHeight, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
// 阻塞块的轮廓图
|
||||
int[][] blockData = getBlockData(blockWidth, blockHeight, blockRadius);
|
||||
@@ -124,7 +123,8 @@ public class CaptchaUtils {
|
||||
waterImage.setRGB(i, j, Color.BLACK.getRGB());
|
||||
blockImage.setRGB(i, j, canvasImage.getRGB(blockX + i, blockY + j));
|
||||
// 轮廓设置为白色,取带像素和无像素的界点,判断该点是不是临界轮廓点
|
||||
if (blockData[i + 1][j] == 0 || blockData[i][j + 1] == 0 || blockData[i - 1][j] == 0 || blockData[i][j - 1] == 0) {
|
||||
if (blockData[i + 1][j] == 0 || blockData[i][j + 1] == 0 || blockData[i - 1][j] == 0
|
||||
|| blockData[i][j - 1] == 0) {
|
||||
blockImage.setRGB(i, j, Color.WHITE.getRGB());
|
||||
waterImage.setRGB(i, j, Color.WHITE.getRGB());
|
||||
}
|
||||
@@ -169,7 +169,8 @@ public class CaptchaUtils {
|
||||
for (int j = 0; j < blockHeight; j++) {
|
||||
data[i][j] = 0;
|
||||
// 创建中间的方形区域
|
||||
if ((i >= blockRadius && i <= blockWidth - blockRadius && j >= blockRadius && j <= blockHeight - blockRadius)) {
|
||||
if ((i >= blockRadius && i <= blockWidth - blockRadius && j >= blockRadius
|
||||
&& j <= blockHeight - blockRadius)) {
|
||||
data[i][j] = 1;
|
||||
}
|
||||
double d1 = Math.pow(i - Objects.requireNonNull(circle1)[0], 2) + Math.pow(j - circle1[1], 2);
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
@@ -14,7 +12,6 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class ConvertUtil {
|
||||
|
||||
|
||||
public static <T> T entityToVo(Object source, Class<T> target) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
@@ -11,6 +7,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
@@ -23,7 +22,8 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url) {
|
||||
@@ -33,8 +33,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param) {
|
||||
@@ -44,9 +46,12 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType 编码类型
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType
|
||||
* 编码类型
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param, String contentType) {
|
||||
@@ -90,8 +95,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String param) {
|
||||
@@ -205,4 +212,4 @@ public class HttpUtils {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import cn.hutool.core.util.RandomUtil;
|
||||
**/
|
||||
public class IdUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 生成8位的UUID
|
||||
*
|
||||
|
||||
@@ -5,6 +5,10 @@ package com.starry.common.utils;
|
||||
* @since 2024/7/25 下午3:15
|
||||
**/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.lionsoul.ip2region.DataBlock;
|
||||
@@ -13,11 +17,6 @@ import org.lionsoul.ip2region.DbSearcher;
|
||||
import org.lionsoul.ip2region.Util;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 根据ip离线查询地址
|
||||
*
|
||||
@@ -74,16 +73,16 @@ public class RegionUtils {
|
||||
int algorithm = DbSearcher.MEMORY_ALGORITYM;
|
||||
Method method = null;
|
||||
switch (algorithm) {
|
||||
case DbSearcher.BTREE_ALGORITHM:
|
||||
case DbSearcher.BTREE_ALGORITHM :
|
||||
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||
break;
|
||||
case DbSearcher.BINARY_ALGORITHM:
|
||||
case DbSearcher.BINARY_ALGORITHM :
|
||||
method = searcher.getClass().getMethod("binarySearch", String.class);
|
||||
break;
|
||||
case DbSearcher.MEMORY_ALGORITYM:
|
||||
case DbSearcher.MEMORY_ALGORITYM :
|
||||
method = searcher.getClass().getMethod("memorySearch", String.class);
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
@@ -103,4 +102,4 @@ public class RegionUtils {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
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;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
@@ -91,8 +89,10 @@ public class ServletUtils {
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param string 待渲染的字符串
|
||||
* @param response
|
||||
* 渲染对象
|
||||
* @param string
|
||||
* 待渲染的字符串
|
||||
*/
|
||||
public static void renderString(HttpServletResponse response, String string) {
|
||||
try {
|
||||
@@ -110,34 +110,27 @@ public class ServletUtils {
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
/*public static boolean isAjaxRequest(HttpServletRequest request)
|
||||
{
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.contains("application/json"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ajax = request.getParameter("__ajax");
|
||||
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
|
||||
}*/
|
||||
/*
|
||||
* public static boolean isAjaxRequest(HttpServletRequest request) { String
|
||||
* accept = request.getHeader("accept"); if (accept != null &&
|
||||
* accept.contains("application/json")) { return true; }
|
||||
*
|
||||
* String xRequestedWith = request.getHeader("X-Requested-With"); if
|
||||
* (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) {
|
||||
* return true; }
|
||||
*
|
||||
* String uri = request.getRequestURI(); if (StringUtils.inStringIgnoreCase(uri,
|
||||
* ".json", ".xml")) { return true; }
|
||||
*
|
||||
* String ajax = request.getParameter("__ajax"); return
|
||||
* StringUtils.inStringIgnoreCase(ajax, "json", "xml"); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* 内容编码
|
||||
*
|
||||
* @param str 内容
|
||||
* @param str
|
||||
* 内容
|
||||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncode(String str) {
|
||||
@@ -151,7 +144,8 @@ public class ServletUtils {
|
||||
/**
|
||||
* 内容解码
|
||||
*
|
||||
* @param str 内容
|
||||
* @param str
|
||||
* 内容
|
||||
* @return 解码后的内容
|
||||
*/
|
||||
public static String urlDecode(String str) {
|
||||
|
||||
@@ -9,8 +9,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* spring工具类 方便在非spring管理环境中获取bean
|
||||
* @author admin spring工具类 方便在非spring管理环境中获取bean
|
||||
* @since 2022/7/28
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 字符串工具类
|
||||
* @author admin 字符串工具类
|
||||
* @since 2022/7/19
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
@@ -22,7 +20,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
*/
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
|
||||
/**
|
||||
* 驼峰转下划线命名
|
||||
*/
|
||||
@@ -65,7 +62,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @param object
|
||||
* Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object) {
|
||||
@@ -75,8 +73,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
* @param object
|
||||
* Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object) {
|
||||
return !isNull(object);
|
||||
@@ -85,8 +84,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* * @return true:为空 false:非空
|
||||
* @param objects
|
||||
* 要判断的对象数组 * @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects) {
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
@@ -95,7 +94,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @param map
|
||||
* 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
@@ -105,7 +105,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @param map
|
||||
* 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
@@ -115,7 +116,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @param coll
|
||||
* 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll) {
|
||||
@@ -125,7 +127,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @param coll
|
||||
* 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
@@ -141,8 +144,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
|
||||
*
|
||||
* @param template 文本模板,被替换的部分用 {} 表示
|
||||
* @param params 参数值
|
||||
* @param template
|
||||
* 文本模板,被替换的部分用 {} 表示
|
||||
* @param params
|
||||
* 参数值
|
||||
* @return 格式化后的文本
|
||||
*/
|
||||
public static String format(String template, Object... params) {
|
||||
@@ -155,8 +160,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断给定的set列表中是否包含数组array 判断给定的数组array中是否包含给定的元素value
|
||||
*
|
||||
* @param collection 给定的集合
|
||||
* @param array 给定的数组
|
||||
* @param collection
|
||||
* 给定的集合
|
||||
* @param array
|
||||
* 给定的数组
|
||||
* @return boolean 结果
|
||||
*/
|
||||
public static boolean containsAny(Collection<String> collection, String... array) {
|
||||
@@ -199,10 +206,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
|
||||
* 例如:HELLO_WORLD -> HelloWorld
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD ->
|
||||
* HelloWorld
|
||||
*
|
||||
* @param name 转换前的下划线大写方式命名的字符串
|
||||
* @param name
|
||||
* 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String convertToCamelCase(String name) {
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 线程相关工具类
|
||||
* @author admin 线程相关工具类
|
||||
* @since 2022/7/25
|
||||
*/
|
||||
public class ThreadsUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ThreadsUtils.class);
|
||||
|
||||
/**
|
||||
* 停止线程池
|
||||
* 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
|
||||
* 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
* 如果仍然超時,則強制退出.
|
||||
* 另对在shutdown时线程本身被调用中断做了处理.
|
||||
* 停止线程池 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 如果超时, 则调用shutdownNow,
|
||||
* 取消在workQueue中Pending的任务,并中断所有阻塞函数. 如果仍然超時,則強制退出. 另对在shutdown时线程本身被调用中断做了处理.
|
||||
*/
|
||||
public static void shutdownAndAwaitTermination(ExecutorService pool) {
|
||||
if (pool != null && !pool.isShutdown()) {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.starry.common.utils.file;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 文件上传工具类
|
||||
* @author admin 文件上传工具类
|
||||
* @since 2022/10/28
|
||||
*/
|
||||
public class FileUploadUtils {
|
||||
@@ -29,5 +27,4 @@ public class FileUploadUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.starry.common.utils.html;
|
||||
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -29,7 +28,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 转义文本中的HTML字符为安全的字符
|
||||
*
|
||||
* @param text 被转义的文本
|
||||
* @param text
|
||||
* 被转义的文本
|
||||
* @return 转义后的文本
|
||||
*/
|
||||
public static String escape(String text) {
|
||||
@@ -39,7 +39,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 还原被转义的HTML特殊字符
|
||||
*
|
||||
* @param content 包含转义符的HTML内容
|
||||
* @param content
|
||||
* 包含转义符的HTML内容
|
||||
* @return 转换后的字符串
|
||||
*/
|
||||
public static String unescape(String content) {
|
||||
@@ -49,7 +50,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 清除所有HTML标签,但是不删除标签内的内容
|
||||
*
|
||||
* @param content 文本
|
||||
* @param content
|
||||
* 文本
|
||||
* @return 清除标签后的文本
|
||||
*/
|
||||
public static String clean(String content) {
|
||||
@@ -59,7 +61,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* Escape编码
|
||||
*
|
||||
* @param text 被编码的文本
|
||||
* @param text
|
||||
* 被编码的文本
|
||||
* @return 编码后的字符
|
||||
*/
|
||||
private static String encode(String text) {
|
||||
@@ -83,7 +86,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* Escape解码
|
||||
*
|
||||
* @param content 被转义的内容
|
||||
* @param content
|
||||
* 被转义的内容
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
public static String decode(String content) {
|
||||
|
||||
@@ -58,7 +58,8 @@ public final class HTMLFilter {
|
||||
**/
|
||||
private final String[] vSelfClosingTags;
|
||||
/**
|
||||
* html elements which must always have separate opening and closing tags (e.g. "<b></b>")
|
||||
* html elements which must always have separate opening and closing tags (e.g.
|
||||
* "<b></b>")
|
||||
**/
|
||||
private final String[] vNeedClosingTags;
|
||||
/**
|
||||
@@ -74,7 +75,8 @@ public final class HTMLFilter {
|
||||
**/
|
||||
private final String[] vAllowedProtocols;
|
||||
/**
|
||||
* tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />")
|
||||
* tags which should be removed if they contain no content (e.g. "<b></b>" or
|
||||
* "<b />")
|
||||
**/
|
||||
private final String[] vRemoveBlanks;
|
||||
/**
|
||||
@@ -87,8 +89,9 @@ public final class HTMLFilter {
|
||||
private final boolean stripComment;
|
||||
private final boolean encodeQuotes;
|
||||
/**
|
||||
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
||||
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
||||
* flag determining whether to try to make tags when presented with "unbalanced"
|
||||
* angle brackets (e.g. "<b text </b>" becomes "<b> text </b>"). If set to
|
||||
* false, unbalanced angle brackets will be html escaped.
|
||||
*/
|
||||
private final boolean alwaysMakeTags;
|
||||
|
||||
@@ -131,7 +134,8 @@ public final class HTMLFilter {
|
||||
/**
|
||||
* Map-parameter configurable constructor.
|
||||
*
|
||||
* @param conf map containing configuration. keys match field names.
|
||||
* @param conf
|
||||
* map containing configuration. keys match field names.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public HTMLFilter(final Map<String, Object> conf) {
|
||||
@@ -194,10 +198,13 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* given a user submitted input String, filter out any invalid or restricted html.
|
||||
* given a user submitted input String, filter out any invalid or restricted
|
||||
* html.
|
||||
*
|
||||
* @param input text (i.e. submitted by a user) than may contain html
|
||||
* @return "clean" version of input, with only valid, whitelisted html elements allowed
|
||||
* @param input
|
||||
* text (i.e. submitted by a user) than may contain html
|
||||
* @return "clean" version of input, with only valid, whitelisted html elements
|
||||
* allowed
|
||||
*/
|
||||
public String filter(final String input) {
|
||||
reset();
|
||||
@@ -326,7 +333,8 @@ public final class HTMLFilter {
|
||||
final String body = m.group(2);
|
||||
String ending = m.group(3);
|
||||
|
||||
// debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
|
||||
// debug( "in a starting tag, name='" + name + "'; body='" + body + "';
|
||||
// ending='" + ending + "'" );
|
||||
if (allowed(name)) {
|
||||
final StringBuilder params = new StringBuilder();
|
||||
|
||||
@@ -494,4 +502,4 @@ public final class HTMLFilter {
|
||||
private boolean allowedAttribute(final String name, final String paramName) {
|
||||
return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.starry.common.utils.http;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import javax.servlet.ServletRequest;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http工具封装
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.starry.common.utils.http;
|
||||
|
||||
import com.starry.common.constant.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
@@ -12,6 +8,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
@@ -24,8 +23,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param) {
|
||||
@@ -35,9 +36,12 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType 编码类型
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType
|
||||
* 编码类型
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param, String contentType) {
|
||||
@@ -81,8 +85,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String param) {
|
||||
@@ -196,4 +202,4 @@ public class HttpUtils {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.starry.common.utils.ip;
|
||||
|
||||
|
||||
import com.starry.common.utils.RegionUtils;
|
||||
import com.starry.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 获取地址工具类
|
||||
* @author admin 获取地址工具类
|
||||
* @since 2022/7/25
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.starry.common.utils.ip;
|
||||
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 获取IP方法
|
||||
@@ -16,7 +14,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 获取客户端IP
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @param request
|
||||
* 请求对象
|
||||
* @return IP地址
|
||||
*/
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
@@ -47,7 +46,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 检查是否为内部IP地址
|
||||
*
|
||||
* @param ip IP地址
|
||||
* @param ip
|
||||
* IP地址
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean internalIp(String ip) {
|
||||
@@ -58,7 +58,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 检查是否为内部IP地址
|
||||
*
|
||||
* @param addr byte地址
|
||||
* @param addr
|
||||
* byte地址
|
||||
* @return 结果
|
||||
*/
|
||||
private static boolean internalIp(byte[] addr) {
|
||||
@@ -77,18 +78,18 @@ public class IpUtils {
|
||||
final byte SECTION_5 = (byte) 0xC0;
|
||||
final byte SECTION_6 = (byte) 0xA8;
|
||||
switch (b0) {
|
||||
case SECTION_1:
|
||||
case SECTION_1 :
|
||||
return true;
|
||||
case SECTION_2:
|
||||
case SECTION_2 :
|
||||
if (b1 >= SECTION_3 && b1 <= SECTION_4) {
|
||||
return true;
|
||||
}
|
||||
case SECTION_5:
|
||||
case SECTION_5 :
|
||||
switch (b1) {
|
||||
case SECTION_6:
|
||||
case SECTION_6 :
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -96,7 +97,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 将IPv4地址转换成字节
|
||||
*
|
||||
* @param text IPv4地址
|
||||
* @param text
|
||||
* IPv4地址
|
||||
* @return byte 字节
|
||||
*/
|
||||
public static byte[] textToNumericFormatV4(String text) {
|
||||
@@ -110,7 +112,7 @@ public class IpUtils {
|
||||
long l;
|
||||
int i;
|
||||
switch (elements.length) {
|
||||
case 1:
|
||||
case 1 :
|
||||
l = Long.parseLong(elements[0]);
|
||||
if ((l < 0L) || (l > 4294967295L)) {
|
||||
return null;
|
||||
@@ -120,7 +122,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 2:
|
||||
case 2 :
|
||||
l = Integer.parseInt(elements[0]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
return null;
|
||||
@@ -134,7 +136,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 3:
|
||||
case 3 :
|
||||
for (i = 0; i < 2; ++i) {
|
||||
l = Integer.parseInt(elements[i]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
@@ -149,7 +151,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 4:
|
||||
case 4 :
|
||||
for (i = 0; i < 4; ++i) {
|
||||
l = Integer.parseInt(elements[i]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
@@ -158,7 +160,7 @@ public class IpUtils {
|
||||
bytes[i] = (byte) (int) (l & 0xFF);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
return null;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -196,7 +198,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 从多级反向代理中获得第一个非unknown IP地址
|
||||
*
|
||||
* @param ip 获得的IP地址
|
||||
* @param ip
|
||||
* 获得的IP地址
|
||||
* @return 第一个非unknown IP地址
|
||||
*/
|
||||
public static String getMultistageReverseProxyIp(String ip) {
|
||||
@@ -216,10 +219,11 @@ public class IpUtils {
|
||||
/**
|
||||
* 检测给定字符串是否为未知,多用于检测HTTP请求相关
|
||||
*
|
||||
* @param checkString 被检测的字符串
|
||||
* @param checkString
|
||||
* 被检测的字符串
|
||||
* @return 是否未知
|
||||
*/
|
||||
public static boolean isUnknown(String checkString) {
|
||||
return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user