fix javadoc warning

This commit is contained in:
Timi
2026-01-04 17:27:36 +08:00
parent ec7f4ecaa9
commit a9156e07f4
32 changed files with 587 additions and 11 deletions

View File

@ -42,6 +42,12 @@ public class TimiSpring {
private static final Logger log = LoggerFactory.getLogger(TimiSpring.class); private static final Logger log = LoggerFactory.getLogger(TimiSpring.class);
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
/**
* 工具类禁止实例化
*/
private TimiSpring() {
}
/** /**
* 回调数据 * 回调数据
* *
@ -102,24 +108,50 @@ public class TimiSpring {
return getServletRequestAttributes().getRequest(); return getServletRequestAttributes().getRequest();
} }
/**
* 获取请求域名
*
* @return 请求域名
*/
public static String getDomain() { public static String getDomain() {
return getRequest().getServerName(); return getRequest().getServerName();
} }
/**
* 获取完整域名(含协议与端口)
*
* @return 完整域名
*/
public static String getFullDomain() { public static String getFullDomain() {
HttpServletRequest req = getRequest(); HttpServletRequest req = getRequest();
String port = req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : ":" + req.getServerPort(); String port = req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : ":" + req.getServerPort();
return "%s://%s%s".formatted(req.getScheme(), getDomain(), port); return "%s://%s%s".formatted(req.getScheme(), getDomain(), port);
} }
/**
* 获取请求 URL
*
* @return 请求 URL
*/
public static String getURL() { public static String getURL() {
return getRequest().getRequestURL().toString(); return getRequest().getRequestURL().toString();
} }
/**
* 获取请求 URI
*
* @return 请求 URI
*/
public static String getURI() { public static String getURI() {
return getRequest().getRequestURI(); return getRequest().getRequestURI();
} }
/**
* 从 URI 指定标记开始截取
*
* @param flag 标记
* @return 截取后的 URI
*/
public static String cutURIStartAt(String flag) { public static String cutURIStartAt(String flag) {
int indexOf = getURI().indexOf(flag); int indexOf = getURI().indexOf(flag);
TimiException.requiredTrue(-1 < indexOf, "not found flag: %s".formatted(flag)); TimiException.requiredTrue(-1 < indexOf, "not found flag: %s".formatted(flag));
@ -315,14 +347,31 @@ public class TimiSpring {
return getRequest().getParameterValues(key); return getRequest().getParameterValues(key);
} }
/**
* 添加 Cookie
*
* @param cookie Cookie
*/
public static void addCookie(Cookie cookie) { public static void addCookie(Cookie cookie) {
getResponse().addCookie(cookie); getResponse().addCookie(cookie);
} }
/**
* 添加 Cookie
*
* @param key 键
* @param value 值
*/
public static void addCookie(String key, String value) { public static void addCookie(String key, String value) {
addCookie(new Cookie(key, value)); addCookie(new Cookie(key, value));
} }
/**
* 获取 Cookie
*
* @param key 键
* @return Cookie
*/
public static Cookie getCookie(String key) { public static Cookie getCookie(String key) {
Cookie[] cookies = getRequest().getCookies(); Cookie[] cookies = getRequest().getCookies();
if (cookies == null) { if (cookies == null) {
@ -345,11 +394,17 @@ public class TimiSpring {
return TimiJava.firstNotEmpty(getHeader("Token"), getHeader("token"), getRequestArg("token"), getRequestArg("Token")); return TimiJava.firstNotEmpty(getHeader("Token"), getHeader("token"), getRequestArg("token"), getRequestArg("Token"));
} }
/**
* 获取原始语言头
*
* @return 语言头
*/
public static String getLanguageRaw() { public static String getLanguageRaw() {
return getHeader("Accept-Language"); return getHeader("Accept-Language");
} }
/** /**
* 获取客户端地区语言
* *
* @return 客户端地区语言 * @return 客户端地区语言
*/ */
@ -399,10 +454,22 @@ public class TimiSpring {
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip; return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
} }
/**
* 是否本地 IP
*
* @return true 为本地 IP
*/
public static boolean isLocalIP() { public static boolean isLocalIP() {
return getRequestIP().startsWith("127"); return getRequestIP().startsWith("127");
} }
/**
* 解析 Range 请求范围
*
* @param fileLength 文件长度
* @return 请求范围
* @throws IOException IO 异常
*/
public static RequestRange requestRange(long fileLength) throws IOException { public static RequestRange requestRange(long fileLength) throws IOException {
HttpServletResponse resp = getResponse(); HttpServletResponse resp = getResponse();

View File

@ -26,10 +26,17 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AOPLogInterceptor { public class AOPLogInterceptor {
/** 全局请求追踪 ID Key */
public static final String REQUEST_ID = "TIMI_SPRING_REQUEST_ID"; public static final String REQUEST_ID = "TIMI_SPRING_REQUEST_ID";
private static final Logger log = LoggerFactory.getLogger(AOPLogInterceptor.class); private static final Logger log = LoggerFactory.getLogger(AOPLogInterceptor.class);
/**
* 创建 AOP 日志拦截器
*/
public AOPLogInterceptor() {
}
/** 注入注解 */ /** 注入注解 */
@Pointcut("@annotation(annotation.com.imyeyu.spring.AOPLog)") @Pointcut("@annotation(annotation.com.imyeyu.spring.AOPLog)")
public void logPointCut() { public void logPointCut() {

View File

@ -18,6 +18,12 @@ public abstract class CaptchaValidAbstractInterceptor {
private boolean enable = true; private boolean enable = true;
/**
* 创建验证码校验拦截器
*/
protected CaptchaValidAbstractInterceptor() {
}
/** 注入注解 */ /** 注入注解 */
@Pointcut("@annotation(com.imyeyu.spring.annotation.CaptchaValid)") @Pointcut("@annotation(com.imyeyu.spring.annotation.CaptchaValid)")
public void captchaPointCut() { public void captchaPointCut() {
@ -45,12 +51,20 @@ public abstract class CaptchaValidAbstractInterceptor {
} }
} }
/**
* 校验验证码
*
* @param captchaId 验证码 ID
* @param captcha 验证码
*/
protected abstract void verify(String captchaId, String captcha); protected abstract void verify(String captchaId, String captcha);
/** 启用校验 */
public void enable() { public void enable() {
enable = true; enable = true;
} }
/** 禁用校验 */
public void disable() { public void disable() {
enable = false; enable = false;
} }

View File

@ -14,6 +14,18 @@ import org.springframework.web.servlet.HandlerInterceptor;
*/ */
public abstract class RequestRateLimitAbstractInterceptor implements HandlerInterceptor { public abstract class RequestRateLimitAbstractInterceptor implements HandlerInterceptor {
/**
* 创建访问频率限制拦截器
*/
protected RequestRateLimitAbstractInterceptor() {
}
/**
* 构建接口标识
*
* @param handlerMethod 方法信息
* @return 接口标识
*/
protected String buildId(HandlerMethod handlerMethod) { protected String buildId(HandlerMethod handlerMethod) {
return handlerMethod.getMethod().getDeclaringClass().getSimpleName() + "." + handlerMethod.getMethod().getName(); return handlerMethod.getMethod().getDeclaringClass().getSimpleName() + "." + handlerMethod.getMethod().getName();
} }

View File

@ -15,9 +15,21 @@ import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.method.support.ModelAndViewContainer;
/**
* 单参数请求解析器
*
* @author 夜雨
* @since 2025-10-13 16:29
*/
@Component @Component
public class RequestSingleParamResolver implements HandlerMethodArgumentResolver { public class RequestSingleParamResolver implements HandlerMethodArgumentResolver {
/**
* 创建单参数解析器
*/
public RequestSingleParamResolver() {
}
@Override @Override
public boolean supportsParameter(MethodParameter parameter) { public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(RequestSingleParam.class); return parameter.hasParameterAnnotation(RequestSingleParam.class);

View File

@ -11,6 +11,7 @@ import java.lang.annotation.Annotation;
/** /**
* 抽象验证令牌 * 抽象验证令牌
* *
* @param <A> 注解类型
* @author 夜雨 * @author 夜雨
* @version 2021-08-16 18:07 * @version 2021-08-16 18:07
*/ */
@ -18,6 +19,11 @@ public abstract class RequiredTokenAbstractInterceptor<A extends Annotation> imp
private final Class<A> annotation; private final Class<A> annotation;
/**
* 创建 Token 验证拦截器
*
* @param annotation 注解类型
*/
public RequiredTokenAbstractInterceptor(Class<A> annotation) { public RequiredTokenAbstractInterceptor(Class<A> annotation) {
this.annotation = annotation; this.annotation = annotation;
} }

View File

@ -17,5 +17,10 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface Column { public @interface Column {
/**
* 指定列名
*
* @return 列名
*/
String value(); String value();
} }

View File

@ -6,6 +6,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* 标记逻辑删除字段并指定存储类型
*
* @author 夜雨 * @author 夜雨
* @since 2025-12-01 10:56 * @since 2025-12-01 10:56
*/ */
@ -13,20 +15,28 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface DeleteColumn { public @interface DeleteColumn {
/**
* 逻辑删除的存储类型
*
* @return 存储类型
*/
Type value() default Type.UNIX; Type value() default Type.UNIX;
/** /**
* * 逻辑删除的时间类型
* *
* @author 夜雨 * @author 夜雨
* @since 2025-12-01 10:57 * @since 2025-12-01 10:57
*/ */
enum Type { enum Type {
/** 毫秒时间戳 */
UNIX, UNIX,
/** 日期 */
DATE, DATE,
/** 日期时间 */
DATE_TIME DATE_TIME
} }
} }

View File

@ -17,5 +17,10 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface Table { public @interface Table {
/**
* 指定表名
*
* @return 表名
*/
String value(); String value();
} }

View File

@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotBlank;
/** /**
* 含验证码数据实体 * 含验证码数据实体
* *
* @param <T> 数据体类型
* @author 夜雨 * @author 夜雨
* @version 2021-03-01 17:10 * @version 2021-03-01 17:10
*/ */
@ -21,26 +22,62 @@ public class CaptchaData<T> {
/** 数据体 */ /** 数据体 */
protected T data; protected T data;
/**
* 创建验证码数据实体
*/
public CaptchaData() {
}
/**
* 获取验证码 ID
*
* @return 验证码 ID
*/
public String getCaptchaId() { public String getCaptchaId() {
return captchaId; return captchaId;
} }
/**
* 设置验证码 ID
*
* @param captchaId 验证码 ID
*/
public void setCaptchaId(String captchaId) { public void setCaptchaId(String captchaId) {
this.captchaId = captchaId; this.captchaId = captchaId;
} }
/**
* 获取验证码
*
* @return 验证码
*/
public String getCaptcha() { public String getCaptcha() {
return captcha; return captcha;
} }
/**
* 设置验证码
*
* @param captcha 验证码
*/
public void setCaptcha(String captcha) { public void setCaptcha(String captcha) {
this.captcha = captcha; this.captcha = captcha;
} }
/**
* 获取数据体
*
* @return 数据体
*/
public T getData() { public T getData() {
return data; return data;
} }
/**
* 设置数据体
*
* @param data 数据体
*/
public void setData(T data) { public void setData(T data) {
this.data = data; this.data = data;
} }

View File

@ -10,21 +10,33 @@ import com.imyeyu.spring.entity.IDEntity;
import com.imyeyu.spring.entity.Updatable; import com.imyeyu.spring.entity.Updatable;
/** /**
* 多语言实体基类
*
* @author 夜雨 * @author 夜雨
* @since 2025-10-17 15:21 * @since 2025-10-17 15:21
*/ */
public class Multilingual extends Language implements IDEntity<String>, Creatable, Updatable, Deletable { public class Multilingual extends Language implements IDEntity<String>, Creatable, Updatable, Deletable {
/** 唯一标识 */
@Id @Id
@AutoUUID @AutoUUID
protected String id; protected String id;
/** 创建时间 */
protected Long createdAt; protected Long createdAt;
/** 更新时间 */
protected Long updatedAt; protected Long updatedAt;
/** 删除时间 */
protected Long deletedAt; protected Long deletedAt;
/**
* 创建多语言实体
*/
public Multilingual() {
}
/** /**
* 获取指定语言值 * 获取指定语言值
* *

View File

@ -10,56 +10,115 @@ import java.util.LinkedHashMap;
/** /**
* 抽象页面查询参数 * 抽象页面查询参数
* *
* @param <T> 查询示例类型
* @author 夜雨 * @author 夜雨
* @version 2023-06-02 14:47 * @version 2023-06-02 14:47
*/ */
public class Page<T> extends BasePage { public class Page<T> extends BasePage {
/** 精确匹配示例 */
protected T equalsExample; protected T equalsExample;
/** 模糊匹配示例 */
protected T likesExample; protected T likesExample;
/** 排序字段映射 */
protected LinkedHashMap<String, BaseMapper.OrderType> orderMap; protected LinkedHashMap<String, BaseMapper.OrderType> orderMap;
/**
* 创建分页参数
*/
public Page() { public Page() {
} }
/**
* 创建分页参数
*
* @param index 页码
* @param size 每页数量
*/
public Page(int index, int size) { public Page(int index, int size) {
super(index, size); super(index, size);
} }
/**
* 获取偏移量
*
* @return 偏移量
*/
public long getOffset() { public long getOffset() {
return (long) index * size; return (long) index * size;
} }
/**
* 获取限制数量
*
* @return 限制数量
*/
public long getLimit() { public long getLimit() {
return size; return size;
} }
/**
* 获取精确匹配示例
*
* @return 精确匹配示例
*/
public T getEqualsExample() { public T getEqualsExample() {
return equalsExample; return equalsExample;
} }
/**
* 设置精确匹配示例
*
* @param equalsExample 精确匹配示例
*/
public void setEqualsExample(T equalsExample) { public void setEqualsExample(T equalsExample) {
this.equalsExample = equalsExample; this.equalsExample = equalsExample;
} }
/**
* 获取模糊匹配示例
*
* @return 模糊匹配示例
*/
public T getLikesExample() { public T getLikesExample() {
return likesExample; return likesExample;
} }
/**
* 设置模糊匹配示例
*
* @param likesExample 模糊匹配示例
*/
public void setLikesExample(T likesExample) { public void setLikesExample(T likesExample) {
this.likesExample = likesExample; this.likesExample = likesExample;
} }
/**
* 获取排序映射
*
* @return 排序映射
*/
public LinkedHashMap<String, BaseMapper.OrderType> getOrderMap() { public LinkedHashMap<String, BaseMapper.OrderType> getOrderMap() {
return orderMap; return orderMap;
} }
/**
* 设置排序映射
*
* @param orderMap 排序映射
*/
public void setOrderMap(LinkedHashMap<String, BaseMapper.OrderType> orderMap) { public void setOrderMap(LinkedHashMap<String, BaseMapper.OrderType> orderMap) {
this.orderMap = orderMap; this.orderMap = orderMap;
} }
/**
* 添加排序字段
*
* @param field 字段名
* @param orderType 排序方式
*/
public void addOrder(String field, BaseMapper.OrderType orderType) { public void addOrder(String field, BaseMapper.OrderType orderType) {
orderMap = TimiJava.defaultIfNull(orderMap, new LinkedHashMap<>()); orderMap = TimiJava.defaultIfNull(orderMap, new LinkedHashMap<>());
orderMap.put(Text.camelCase2underscore(field), orderType); orderMap.put(Text.camelCase2underscore(field), orderType);

View File

@ -5,8 +5,15 @@ import com.imyeyu.java.bean.BasePageResult;
/** /**
* 抽象页面查询结果 * 抽象页面查询结果
* *
* @param <T> 列表元素类型
* @author 夜雨 * @author 夜雨
* @version 2023-06-02 14:47 * @version 2023-06-02 14:47
*/ */
public class PageResult<T> extends BasePageResult<T> { public class PageResult<T> extends BasePageResult<T> {
/**
* 创建分页结果
*/
public PageResult() {
}
} }

View File

@ -8,6 +8,12 @@ package com.imyeyu.spring.bean;
*/ */
public class RedisConfigParams { public class RedisConfigParams {
/**
* 创建 Redis 配置参数
*/
public RedisConfigParams() {
}
/** 地址 */ /** 地址 */
private String host; private String host;

View File

@ -1,39 +1,75 @@
package com.imyeyu.spring.bean; package com.imyeyu.spring.bean;
/** /**
* 请求范围参数
*
* @author 夜雨 * @author 夜雨
* @since 2025-07-14 17:09 * @since 2025-07-14 17:09
*/ */
public class RequestRange { public class RequestRange {
/** 起始值 */
private long start; private long start;
/** 结束值 */
private long end; private long end;
/** 范围长度 */
private long length; private long length;
/**
* 创建请求范围
*
* @param start 起始值
* @param end 结束值
*/
public RequestRange(long start, long end) { public RequestRange(long start, long end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
} }
/**
* 获取起始值
*
* @return 起始值
*/
public long getStart() { public long getStart() {
return start; return start;
} }
/**
* 设置起始值
*
* @param start 起始值
*/
public void setStart(long start) { public void setStart(long start) {
this.start = start; this.start = start;
} }
/**
* 获取结束值
*
* @return 结束值
*/
public long getEnd() { public long getEnd() {
return end; return end;
} }
/**
* 设置结束值
*
* @param end 结束值
*/
public void setEnd(long end) { public void setEnd(long end) {
this.end = end; this.end = end;
} }
/**
* 获取范围长度
*
* @return 范围长度
*/
public long getLength() { public long getLength() {
return end - start + 1; return end - start + 1;
} }
} }

View File

@ -21,6 +21,12 @@ import java.time.Duration;
* @version 2021-11-21 10:00 * @version 2021-11-21 10:00
*/ */
public abstract class AbstractRedisConfig implements CachingConfigurer { public abstract class AbstractRedisConfig implements CachingConfigurer {
/**
* 创建 Redis 配置
*/
protected AbstractRedisConfig() {
}
/** /**
* 构建 Redis 基本配置 * 构建 Redis 基本配置

View File

@ -13,6 +13,12 @@ import java.io.Serializable;
*/ */
public class BaseEntity implements Serializable, Creatable, Updatable, Deletable { public class BaseEntity implements Serializable, Creatable, Updatable, Deletable {
/**
* 创建基础实体
*/
public BaseEntity() {
}
/** 创建时间 */ /** 创建时间 */
protected Long createdAt; protected Long createdAt;

View File

@ -14,6 +14,12 @@ public class Entity extends BaseEntity implements IDEntity<Long> {
@Id @Id
protected Long id; protected Long id;
/**
* 创建基础 ID 实体
*/
public Entity() {
}
/** /**
* 获取 ID * 获取 ID
* *

View File

@ -3,6 +3,7 @@ package com.imyeyu.spring.entity;
/** /**
* ID 实体 * ID 实体
* *
* @param <T> ID 类型
* @author 夜雨 * @author 夜雨
* @since 2025-02-07 17:10 * @since 2025-02-07 17:10
*/ */

View File

@ -16,6 +16,12 @@ public class UUIDEntity extends BaseEntity implements IDEntity<String> {
@AutoUUID @AutoUUID
protected String id; protected String id;
/**
* 创建 UUID 实体
*/
public UUIDEntity() {
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@ -19,6 +19,12 @@ import java.sql.SQLException;
*/ */
public class GsonHandler extends BaseTypeHandler<JsonElement> { public class GsonHandler extends BaseTypeHandler<JsonElement> {
/**
* 创建 Gson 类型处理器
*/
public GsonHandler() {
}
@Override @Override
public void setNonNullParameter(PreparedStatement ps, int i, JsonElement parameter, JdbcType jdbcType) throws SQLException { public void setNonNullParameter(PreparedStatement ps, int i, JsonElement parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i, parameter.toString()); ps.setString(i, parameter.toString());

View File

@ -14,6 +14,8 @@ import java.util.List;
/** /**
* 基本 SQL 映射,子接口可以不实现 * 基本 SQL 映射,子接口可以不实现
* *
* @param <T> 实体类型
* @param <P> 主键类型
* @author 夜雨 * @author 夜雨
* @version 2021-07-16 09:40 * @version 2021-07-16 09:40
*/ */
@ -27,17 +29,23 @@ public interface BaseMapper<T, P> {
*/ */
enum OrderType { enum OrderType {
/** 升序 */
ASC, ASC,
/** 降序 */
DESC DESC
} }
/** 未删除条件 */
String NOT_DELETE = " AND `deleted_at` IS NULL "; String NOT_DELETE = " AND `deleted_at` IS NULL ";
/** 限制一条 */
String LIMIT_1 = " LIMIT 1"; String LIMIT_1 = " LIMIT 1";
/** 当前时间戳毫秒 */
String UNIX_TIME = " FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000) "; String UNIX_TIME = " FLOOR(UNIX_TIMESTAMP(NOW(3)) * 1000) ";
/** 分页限制 */
String PAGE = NOT_DELETE + " LIMIT #{offset}, #{limit}"; String PAGE = NOT_DELETE + " LIMIT #{offset}, #{limit}";
/** /**
@ -71,6 +79,11 @@ public interface BaseMapper<T, P> {
return result; return result;
} }
/**
* 查询全部数据
*
* @return 数据列表
*/
@SelectProvider(type = SQLProvider.class, method = "selectAll") @SelectProvider(type = SQLProvider.class, method = "selectAll")
List<T> selectAll(); List<T> selectAll();
@ -92,9 +105,21 @@ public interface BaseMapper<T, P> {
@SelectProvider(type = SQLProvider.class, method = "select") @SelectProvider(type = SQLProvider.class, method = "select")
T select(P id); T select(P id);
/**
* 根据示例查询单条数据
*
* @param t 示例对象
* @return 数据对象
*/
@SelectProvider(type = SQLProvider.class, method = "selectByExample") @SelectProvider(type = SQLProvider.class, method = "selectByExample")
T selectByExample(T t); T selectByExample(T t);
/**
* 根据示例查询全部数据
*
* @param t 示例对象
* @return 数据列表
*/
@SelectProvider(type = SQLProvider.class, method = "selectAllByExample") @SelectProvider(type = SQLProvider.class, method = "selectAllByExample")
List<T> selectAllByExample(T t); List<T> selectAllByExample(T t);
@ -106,6 +131,11 @@ public interface BaseMapper<T, P> {
@UpdateProvider(type = SQLProvider.class, method = "update") @UpdateProvider(type = SQLProvider.class, method = "update")
void update(T t); void update(T t);
/**
* 选择性更新
*
* @param t 数据对象
*/
@UpdateProvider(type = SQLProvider.class, method = "updateSelective") @UpdateProvider(type = SQLProvider.class, method = "updateSelective")
void updateSelective(T t); void updateSelective(T t);
@ -117,6 +147,11 @@ public interface BaseMapper<T, P> {
@UpdateProvider(type = SQLProvider.class, method = "delete") @UpdateProvider(type = SQLProvider.class, method = "delete")
void delete(P id); void delete(P id);
/**
* 根据示例批量逻辑删除
*
* @param t 示例对象
*/
@UpdateProvider(type = SQLProvider.class, method = "deleteAllByExample") @UpdateProvider(type = SQLProvider.class, method = "deleteAllByExample")
void deleteAllByExample(T t); void deleteAllByExample(T t);

View File

@ -20,7 +20,17 @@ public abstract class AbstractEntityService<T, P> implements BaseService<T, P> {
/** 基本 Mapper */ /** 基本 Mapper */
protected BaseMapper<T, P> baseMapper; protected BaseMapper<T, P> baseMapper;
/** @return Mapper 实例 */ /**
* 创建实体服务
*/
protected AbstractEntityService() {
}
/**
* 获取 Mapper 实例
*
* @return Mapper 实例
*/
protected abstract BaseMapper<T, P> mapper(); protected abstract BaseMapper<T, P> mapper();
/** 检查 mapper */ /** 检查 mapper */

View File

@ -5,6 +5,7 @@ import com.imyeyu.java.bean.timi.TimiException;
/** /**
* 可软删除实体服务 * 可软删除实体服务
* *
* @param <P> 主键类型
* @author 夜雨 * @author 夜雨
* @since 2025-05-14 17:30 * @since 2025-05-14 17:30
*/ */

View File

@ -5,6 +5,7 @@ import com.imyeyu.java.bean.timi.TimiException;
/** /**
* 可销毁(物理删除)实体服务 * 可销毁(物理删除)实体服务
* *
* @param <P> 主键类型
* @author 夜雨 * @author 夜雨
* @since 2025-05-14 17:30 * @since 2025-05-14 17:30
*/ */

View File

@ -9,11 +9,19 @@ import java.lang.annotation.Annotation;
/** /**
* 数据验证动态消息返回抽象类 * 数据验证动态消息返回抽象类
* *
* @param <A> 注解类型
* @param <T> 校验数据类型
* @author 夜雨 * @author 夜雨
* @version 2023-05-07 00:08 * @version 2023-05-07 00:08
*/ */
public abstract class AbstractValidator<A extends Annotation, T> implements ConstraintValidator<A, T> { public abstract class AbstractValidator<A extends Annotation, T> implements ConstraintValidator<A, T> {
/**
* 创建校验器
*/
protected AbstractValidator() {
}
/** /**
* 验证处理器,入参验证数据,返回错误消息语言映射,返回 null 时表示通过验证 * 验证处理器,入参验证数据,返回错误消息语言映射,返回 null 时表示通过验证
* *
@ -32,4 +40,4 @@ public abstract class AbstractValidator<A extends Annotation, T> implements Cons
} }
return true; return true;
} }
} }

View File

@ -28,12 +28,20 @@ public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
private static final String DEV_LANG_CONFIG = "dev.lang"; private static final String DEV_LANG_CONFIG = "dev.lang";
/**
* 创建全局异常处理器
*/
public GlobalExceptionHandler() {
}
@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
private String env; private String env;
/** /**
* @param e * 消息转换异常
* @return *
* @param e 异常
* @return 异常返回
*/ */
@ExceptionHandler(HttpMessageConversionException.class) @ExceptionHandler(HttpMessageConversionException.class)
public TimiResponse<?> conversionException(HttpMessageConversionException e) { public TimiResponse<?> conversionException(HttpMessageConversionException e) {

View File

@ -32,8 +32,15 @@ public class GlobalReturnHandler implements ResponseBodyAdvice<Object> {
private static final Logger log = LoggerFactory.getLogger(GlobalReturnHandler.class); private static final Logger log = LoggerFactory.getLogger(GlobalReturnHandler.class);
/** 多语言头处理回调 */
private CallbackArgReturn<LanguageMsgMapping<?>, String> multilingualHeader; private CallbackArgReturn<LanguageMsgMapping<?>, String> multilingualHeader;
/**
* 创建全局返回处理器
*/
public GlobalReturnHandler() {
}
@Override @Override
public boolean supports(@NonNull MethodParameter returnType, @NonNull Class<? extends HttpMessageConverter<?>> converterType) { public boolean supports(@NonNull MethodParameter returnType, @NonNull Class<? extends HttpMessageConverter<?>> converterType) {
return Objects.requireNonNull(returnType.getMethod()).getAnnotation(IgnoreGlobalReturn.class) == null; return Objects.requireNonNull(returnType.getMethod()).getAnnotation(IgnoreGlobalReturn.class) == null;
@ -71,10 +78,20 @@ public class GlobalReturnHandler implements ResponseBodyAdvice<Object> {
return result; return result;
} }
/**
* 获取多语言头处理回调
*
* @return 处理回调
*/
public CallbackArgReturn<LanguageMsgMapping<?>, String> getMultilingualHeader() { public CallbackArgReturn<LanguageMsgMapping<?>, String> getMultilingualHeader() {
return multilingualHeader; return multilingualHeader;
} }
/**
* 设置多语言头处理回调
*
* @param multilingualHeader 处理回调
*/
public void setMultilingualHeader(CallbackArgReturn<LanguageMsgMapping<?>, String> multilingualHeader) { public void setMultilingualHeader(CallbackArgReturn<LanguageMsgMapping<?>, String> multilingualHeader) {
this.multilingualHeader = multilingualHeader; this.multilingualHeader = multilingualHeader;
} }

View File

@ -22,6 +22,8 @@ import java.util.function.Consumer;
* RedisTemplate 功能封装,简化 Redis 操作 * RedisTemplate 功能封装,简化 Redis 操作
* <p>serializer 为该 RedisTemplate 的键的序列化操作,序列化解析器由 {@link AbstractRedisConfig} 提供 * <p>serializer 为该 RedisTemplate 的键的序列化操作,序列化解析器由 {@link AbstractRedisConfig} 提供
* *
* @param <K> 键类型
* @param <V> 值类型
* @author 夜雨 * @author 夜雨
* @version 2021-11-21 09:58 * @version 2021-11-21 09:58
*/ */
@ -30,6 +32,12 @@ public class Redis<K, V> {
private final RedisSerializer<K> serializer; private final RedisSerializer<K> serializer;
private final RedisTemplate<K, V> redis; private final RedisTemplate<K, V> redis;
/**
* 创建 Redis 操作封装
*
* @param redis RedisTemplate 实例
* @param serializer 键序列化器
*/
public Redis(RedisTemplate<K, V> redis, RedisSerializer<K> serializer) { public Redis(RedisTemplate<K, V> redis, RedisSerializer<K> serializer) {
this.redis = redis; this.redis = redis;
this.serializer = serializer; this.serializer = serializer;
@ -47,9 +55,9 @@ public class Redis<K, V> {
/** /**
* 加锁 * 加锁
* *
* @param key * @param key
* @param value * @param value
* @param timeoutMS * @param timeoutMS 超时时间毫秒
* @return true 为加锁成功 * @return true 为加锁成功
*/ */
public boolean lock(K key, V value, long timeoutMS) { public boolean lock(K key, V value, long timeoutMS) {
@ -57,6 +65,11 @@ public class Redis<K, V> {
return lock != null && lock; return lock != null && lock;
} }
/**
* 释放锁
*
* @param key 键
*/
public void releaseLock(K key) { public void releaseLock(K key) {
destroy(key); destroy(key);
} }

View File

@ -8,11 +8,17 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /**
* Redis 序列化工具
*
* @author 夜雨 * @author 夜雨
* @version 2023-07-17 16:20 * @version 2023-07-17 16:20
*/ */
public class RedisSerializers { public class RedisSerializers {
/** 工具类禁止实例化 */
private RedisSerializers() {
}
/** 字符串序列化 */ /** 字符串序列化 */
public static final StringRedisSerializer STRING = new StringRedisSerializer(); public static final StringRedisSerializer STRING = new StringRedisSerializer();
@ -76,7 +82,13 @@ public class RedisSerializers {
} }
}; };
/** Gson 序列化 */ /**
* Gson 序列化
*
* @param <T> 数据类型
* @param clazz 数据类型
* @return Redis 序列化器
*/
public static <T> RedisSerializer<T> gsonSerializer(Class<T> clazz) { public static <T> RedisSerializer<T> gsonSerializer(Class<T> clazz) {
return new RedisSerializer<>() { return new RedisSerializer<>() {

View File

@ -45,6 +45,12 @@ public class SQLProvider {
/** 反射缓存 */ /** 反射缓存 */
private static final Map<Class<?>, EntityMeta> ENTITY_META_CACHE = new ConcurrentHashMap<>(); private static final Map<Class<?>, EntityMeta> ENTITY_META_CACHE = new ConcurrentHashMap<>();
/**
* 创建 SQL 提供器
*/
public SQLProvider() {
}
/** /**
* 根据 Page 对象查询数据列表 * 根据 Page 对象查询数据列表
* *
@ -148,6 +154,12 @@ public class SQLProvider {
return sql.toString(); return sql.toString();
} }
/**
* 查询全部数据
*
* @param context 代理器上下文
* @return SQL
*/
public String selectAll(ProviderContext context) { public String selectAll(ProviderContext context) {
EntityMeta meta = getEntityMeta(context); EntityMeta meta = getEntityMeta(context);
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
@ -162,6 +174,7 @@ public class SQLProvider {
* 插入 * 插入
* <p><i>不实现 {@link Creatable} 也允许调用是合理的,某些数据属于关联数据,不参与主创建过程</i></p> * <p><i>不实现 {@link Creatable} 也允许调用是合理的,某些数据属于关联数据,不参与主创建过程</i></p>
* *
* @param context 代理器上下文
* @param entity 实体 * @param entity 实体
* @return SQL * @return SQL
*/ */
@ -299,6 +312,12 @@ public class SQLProvider {
return "UPDATE `%s` SET `deleted_at` = %s WHERE `%s` = #{id}".formatted(meta.table, Time.now(), meta.idFieldColumn.columnName); return "UPDATE `%s` SET `deleted_at` = %s WHERE `%s` = #{id}".formatted(meta.table, Time.now(), meta.idFieldColumn.columnName);
} }
/**
* 根据示例批量逻辑删除
*
* @param entity 实体
* @return SQL
*/
public String deleteAllByExample(Object entity) { public String deleteAllByExample(Object entity) {
EntityMeta meta = getEntityMeta(entity.getClass()); EntityMeta meta = getEntityMeta(entity.getClass());
TimiException.required(meta.canDelete, "not allow delete for %s".formatted(meta.entityClass)); TimiException.required(meta.canDelete, "not allow delete for %s".formatted(meta.entityClass));
@ -398,6 +417,11 @@ public class SQLProvider {
/** true 为可销毁(硬删除) */ /** true 为可销毁(硬删除) */
final boolean canDestroy; final boolean canDestroy;
/**
* 创建实体元数据
*
* @param entityClass 实体类型
*/
public EntityMeta(Class<?> entityClass) { public EntityMeta(Class<?> entityClass) {
this.entityClass = entityClass; this.entityClass = entityClass;
@ -459,38 +483,83 @@ public class SQLProvider {
return sb.substring(0, sb.length() - 1); return sb.substring(0, sb.length() - 1);
} }
/**
* 获取实体类型
*
* @return 实体类型
*/
public Class<?> getEntityClass() { public Class<?> getEntityClass() {
return entityClass; return entityClass;
} }
/**
* 获取表名
*
* @return 表名
*/
public String getTable() { public String getTable() {
return table; return table;
} }
/**
* 获取查询字段映射
*
* @return 查询字段映射
*/
public String getSelectAllClause() { public String getSelectAllClause() {
return selectAllClause; return selectAllClause;
} }
/**
* 获取 ID 字段映射
*
* @return ID 字段映射
*/
public FieldColumn getIdFieldColumn() { public FieldColumn getIdFieldColumn() {
return idFieldColumn; return idFieldColumn;
} }
/**
* 获取字段映射列表
*
* @return 字段映射列表
*/
public List<FieldColumn> getFieldColumnList() { public List<FieldColumn> getFieldColumnList() {
return fieldColumnList; return fieldColumnList;
} }
/**
* 是否可创建
*
* @return true 为可创建
*/
public boolean canCreate() { public boolean canCreate() {
return canCreate; return canCreate;
} }
/**
* 是否可更新
*
* @return true 为可更新
*/
public boolean canUpdate() { public boolean canUpdate() {
return canUpdate; return canUpdate;
} }
/**
* 是否可删除
*
* @return true 为可删除
*/
public boolean canDelete() { public boolean canDelete() {
return canDelete; return canDelete;
} }
/**
* 是否可销毁
*
* @return true 为可销毁
*/
public boolean canDestroy() { public boolean canDestroy() {
return canDestroy; return canDestroy;
} }
@ -525,6 +594,11 @@ public class SQLProvider {
final DeleteColumn.Type deleteColumnType; final DeleteColumn.Type deleteColumnType;
/**
* 创建字段映射
*
* @param field 字段
*/
public FieldColumn(Field field) { public FieldColumn(Field field) {
this.field = field; this.field = field;
@ -551,6 +625,12 @@ public class SQLProvider {
} }
} }
/**
* 判断字段值是否为空
*
* @param entity 实体
* @return true 为 null
*/
public boolean isNull(Object entity) { public boolean isNull(Object entity) {
try { try {
return Ref.getFieldValue(entity, field, Object.class) == null; return Ref.getFieldValue(entity, field, Object.class) == null;
@ -559,10 +639,22 @@ public class SQLProvider {
} }
} }
/**
* 判断字段值是否非空
*
* @param entity 实体
* @return true 为非 null
*/
public boolean isNotNull(Object entity) { public boolean isNotNull(Object entity) {
return !isNull(entity); return !isNull(entity);
} }
/**
* 判断字段值是否为空
*
* @param entity 实体
* @return true 为空
*/
public boolean isEmpty(Object entity) { public boolean isEmpty(Object entity) {
try { try {
return TimiJava.isEmpty(Ref.getFieldValue(entity, field, Object.class)); return TimiJava.isEmpty(Ref.getFieldValue(entity, field, Object.class));
@ -571,10 +663,22 @@ public class SQLProvider {
} }
} }
/**
* 判断字段值是否非空
*
* @param entity 实体
* @return true 为非空
*/
public boolean isNotEmpty(Object entity) { public boolean isNotEmpty(Object entity) {
return !isEmpty(entity); return !isEmpty(entity);
} }
/**
* 获取字段字符串值
*
* @param obj 实体
* @return 字符串值
*/
public String getAsString(Object obj) { public String getAsString(Object obj) {
try { try {
return field.get(obj).toString(); return field.get(obj).toString();
@ -583,30 +687,65 @@ public class SQLProvider {
} }
} }
/**
* 获取字段
*
* @return 字段
*/
public Field getField() { public Field getField() {
return field; return field;
} }
/**
* 获取字段名
*
* @return 字段名
*/
public String getFieldName() { public String getFieldName() {
return fieldName; return fieldName;
} }
/**
* 获取列名
*
* @return 列名
*/
public String getColumnName() { public String getColumnName() {
return columnName; return columnName;
} }
/**
* 是否为 ID 字段
*
* @return true 为 ID 字段
*/
public boolean isId() { public boolean isId() {
return isId; return isId;
} }
/**
* 是否非 ID 字段
*
* @return true 为非 ID 字段
*/
public boolean isNotId() { public boolean isNotId() {
return !isId(); return !isId();
} }
/**
* 是否自动 UUID
*
* @return true 为自动 UUID
*/
public boolean isAutoUUID() { public boolean isAutoUUID() {
return isAutoUUID; return isAutoUUID;
} }
/**
* 是否自动大写 UUID
*
* @return true 为自动大写 UUID
*/
public boolean isAutoUpperUUID() { public boolean isAutoUpperUUID() {
return isAutoUpperUUID; return isAutoUpperUUID;
} }

View File

@ -9,13 +9,19 @@ import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
* * Yaml 属性源加载工厂
* *
* @author 夜雨 * @author 夜雨
* @since 2025-10-13 16:29 * @since 2025-10-13 16:29
*/ */
public class YamlPropertySourceFactory implements PropertySourceFactory { public class YamlPropertySourceFactory implements PropertySourceFactory {
/**
* 创建 Yaml 属性源工厂
*/
public YamlPropertySourceFactory() {
}
@Override @Override
public @org.springframework.lang.NonNull PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException { public @org.springframework.lang.NonNull PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
List<PropertySource<?>> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource()); List<PropertySource<?>> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource());