2、自定义Jackson starter
This commit is contained in:
Vendored
+15
-13
@@ -20,10 +20,11 @@
|
||||
"body": [
|
||||
"/**",
|
||||
" *",
|
||||
" * @Title: ${TM_FILENAME_BASE}",
|
||||
" * @Description: ${1:}",
|
||||
" * @Author: ${2:}",
|
||||
" * @Date: ${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
" * @author ${2:}",
|
||||
" * @version V1.0",
|
||||
" * @title ${TM_FILENAME_BASE}",
|
||||
" * @description ${1:}",
|
||||
" * @date${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
" */"
|
||||
],
|
||||
"description": "生成类注释"
|
||||
@@ -33,10 +34,11 @@
|
||||
"body": [
|
||||
"/**",
|
||||
" *",
|
||||
" * @Title: ${TM_FILENAME_BASE}",
|
||||
" * @Description: ${1:}",
|
||||
" * @Author: ${2:}",
|
||||
" * @Date: ${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
" * @author ${2:}",
|
||||
" * @version V1.0",
|
||||
" * @title ${TM_FILENAME_BASE}",
|
||||
" * @description ${1:}",
|
||||
" * @date${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
" */"
|
||||
],
|
||||
"description": "生成接口注释"
|
||||
@@ -46,11 +48,11 @@
|
||||
"body": [
|
||||
"/**",
|
||||
" *",
|
||||
" * @Title: ${TM_FILENAME_BASE}",
|
||||
" * @Description: ${1:}",
|
||||
" * @Author: ${2:}",
|
||||
" * @Date: ${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
" */"
|
||||
" * @author ${2:}",
|
||||
" * @version V1.0",
|
||||
" * @title ${TM_FILENAME_BASE}",
|
||||
" * @description ${1:}",
|
||||
" * @date${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}",
|
||||
],
|
||||
"description": "生成注解注释"
|
||||
},
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
||||
"name": "Spring Boot-XiaoyiAuthApplication<xiaoyi-auth>",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"mainClass": "top.crushtj.xiaoyishu.auth.XiaoyiAuthApplication",
|
||||
"mainClass": "com.jy.xiaoyishu.auth.XiaoyiAuthApplication",
|
||||
"projectName": "xiaoyi-auth",
|
||||
"args": "",
|
||||
"envFile": "${workspaceFolder}/.env"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyishu</artifactId>
|
||||
<version>${revision}</version>
|
||||
|
||||
@@ -48,16 +48,23 @@
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- 业务接口日志组件 -->
|
||||
<dependency>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-spring-boot-starter-biz-operationlog</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务接口日志组件 -->
|
||||
<dependency>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-spring-boot-starter-jackson</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- Spring Boot 官方依赖管理 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+9
-3
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- 指定父项目 -->
|
||||
<parent>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyishu</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
@@ -19,14 +19,20 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-common</artifactId>
|
||||
</dependency>
|
||||
<!-- 业务接口日志组件 -->
|
||||
<dependency>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-spring-boot-starter-biz-operationlog</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Jackson-->
|
||||
<dependency>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-spring-boot-starter-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.jy.xiaoyishu.auth;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title XiaoyiAuthApplication
|
||||
* @description 启动类
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class XiaoyiAuthApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XiaoyiAuthApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.xiaoyishu.auth.config;
|
||||
package com.jy.xiaoyishu.auth.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
@@ -8,14 +8,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanfuye
|
||||
* @author ayi
|
||||
* @title MyBatisConfig
|
||||
* @date 2025/11/27
|
||||
* @description MybatisPlus配置类
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@MapperScan("top.crushtj.**.mappers")
|
||||
@MapperScan("com.jy.**.mappers")
|
||||
public class MybatisPlusConfig {
|
||||
/**
|
||||
* 分页插件
|
||||
+9
-14
@@ -1,21 +1,21 @@
|
||||
package top.crushtj.xiaoyishu.auth.controller;
|
||||
package com.jy.xiaoyishu.auth.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.crushtj.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import top.crushtj.framework.common.response.Response;
|
||||
import top.crushtj.xiaoyishu.auth.vo.User;
|
||||
import com.jy.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.jy.framework.common.response.Response;
|
||||
import com.jy.xiaoyishu.auth.vo.User;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: TestController
|
||||
* @Description: 测试控制器
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/21
|
||||
* @author ayi
|
||||
* @title TestController
|
||||
* @description 测试控制器
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@@ -24,12 +24,7 @@ public class TestController {
|
||||
@GetMapping("/test")
|
||||
@ApiOperationLog(description = "测试接口")
|
||||
public Response<User> testController() {
|
||||
return Response.success(User.builder()
|
||||
.id(1L)
|
||||
.name("ayi")
|
||||
.age(18)
|
||||
.createTime(LocalDateTime.now())
|
||||
.build());
|
||||
return Response.success(User.builder().id(1L).name("ayi").age(18).createTime(LocalDateTime.now()).build());
|
||||
}
|
||||
|
||||
@PostMapping("/test2")
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.xiaoyishu.auth.domain.entity;
|
||||
package com.jy.xiaoyishu.auth.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package top.crushtj.xiaoyishu.auth.domain.mappers;
|
||||
package com.jy.xiaoyishu.auth.domain.mappers;
|
||||
|
||||
import top.crushtj.xiaoyishu.auth.domain.entity.UserEntity;
|
||||
import com.jy.xiaoyishu.auth.domain.entity.UserEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.crushtj.xiaoyishu.auth.domain.mappers.UserMapper">
|
||||
<mapper namespace="com.jy.xiaoyishu.auth.domain.mappers.UserMapper">
|
||||
|
||||
<resultMap type="top.crushtj.xiaoyishu.auth.domain.entity.UserEntity" id="UserMap">
|
||||
<resultMap type="com.jy.xiaoyishu.auth.domain.entity.UserEntity" id="UserMap">
|
||||
<result property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.xiaoyishu.auth.vo;
|
||||
package com.jy.xiaoyishu.auth.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -10,10 +10,10 @@ import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: User
|
||||
* @Description: 测试用户类
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/26
|
||||
* @author ayi
|
||||
* @title User
|
||||
* @description 测试用户类
|
||||
* @date 2025/11/26
|
||||
*/
|
||||
|
||||
@Data
|
||||
@@ -1,13 +0,0 @@
|
||||
package top.crushtj.xiaoyishu.auth;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class XiaoyiAuthApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XiaoyiAuthApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,14 +51,14 @@ spring:
|
||||
mybatis-plus:
|
||||
mapper-locations:
|
||||
- classpath*:top/crushtj/**/*.xml # 匹配所有模块中的 Mapper XML 文件
|
||||
type-aliases-package: top.crushtj.xiaoyishu.auth.domain.entity # 实体类包路径
|
||||
type-aliases-package: com.jy.xiaoyishu.auth.domain.entity # 实体类包路径
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true # 开启驼峰命名转换
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志输出(调试用)
|
||||
|
||||
logging:
|
||||
level:
|
||||
top.crushtj.xiaoyishu.auth.domain.mappers: debug
|
||||
com.jy.xiaoyishu.auth.domain.mappers: debug
|
||||
config: classpath:config/logback-dev.xml
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.xiaoyishu.auth;
|
||||
package com.jy.xiaoyishu.auth;
|
||||
|
||||
import com.alibaba.druid.filter.config.ConfigTools;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -7,10 +7,10 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* @author hanfuye
|
||||
* @author ayi
|
||||
* @version V1.0
|
||||
* @Title: DruidTest
|
||||
* @Description:
|
||||
* @title DruidTest
|
||||
* @description
|
||||
* @date 2025/12/01
|
||||
*/
|
||||
|
||||
+14
-8
@@ -1,15 +1,23 @@
|
||||
package top.crushtj.xiaoyishu.auth;
|
||||
package com.jy.xiaoyishu.auth;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import top.crushtj.xiaoyishu.auth.domain.entity.UserEntity;
|
||||
import top.crushtj.xiaoyishu.auth.domain.mappers.UserMapper;
|
||||
import com.jy.xiaoyishu.auth.domain.entity.UserEntity;
|
||||
import com.jy.xiaoyishu.auth.domain.mappers.UserMapper;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title XiaoyiAuthApplicationTests
|
||||
* @description 测试类
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
class XiaoyiAuthApplicationTests {
|
||||
@@ -23,17 +31,15 @@ class XiaoyiAuthApplicationTests {
|
||||
|
||||
@Test
|
||||
void testInsert() {
|
||||
UserEntity user = UserEntity.builder()
|
||||
.username("刑加一")
|
||||
.createTime(LocalDateTime.now())
|
||||
.updateTime(LocalDateTime.now())
|
||||
UserEntity user =
|
||||
UserEntity.builder().username("刑加一").createTime(LocalDateTime.now()).updateTime(LocalDateTime.now())
|
||||
.build();
|
||||
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryTest(){
|
||||
void queryTest() {
|
||||
LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserEntity::getUsername, "刑加一");
|
||||
UserEntity user = userMapper.selectOne(queryWrapper);
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyishu</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
@@ -16,8 +16,12 @@
|
||||
<description>平台基础设施层:封装一些常用功能,供各个业务线拿来即用</description>
|
||||
|
||||
<modules>
|
||||
<!--通用-->
|
||||
<module>xiaoyi-common</module>
|
||||
<!--日志切面-->
|
||||
<module>xiaoyi-spring-boot-starter-biz-operationlog</module>
|
||||
<!--Jackson-->
|
||||
<module>xiaoyi-spring-boot-starter-jackson</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
@@ -36,6 +36,12 @@
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- AOP 切面 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+5
-5
@@ -1,12 +1,12 @@
|
||||
package top.crushtj.framework.common.constant;
|
||||
package com.jy.framework.common.constant;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @Title: DateConstants
|
||||
* @Description: 日期常量
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/26
|
||||
* @author ayi
|
||||
* @title DateConstants
|
||||
* @description 日期常量
|
||||
* @date 2025/11/26
|
||||
*/
|
||||
public interface DateConstants {
|
||||
/**
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.jy.framework.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title BaseExceptionInterface
|
||||
* @description 基础异常接口
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
public interface BaseExceptionInterface {
|
||||
/**
|
||||
* 获取异常码
|
||||
*
|
||||
* @return 异常码
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* 获取异常信息
|
||||
*
|
||||
* @return 异常信息
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.jy.framework.common.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title BusiException
|
||||
* @description 业务异常
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 异常码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param baseExceptionInterface 基础异常接口
|
||||
*/
|
||||
public BizException(BaseExceptionInterface baseExceptionInterface) {
|
||||
this.code = baseExceptionInterface.getCode();
|
||||
this.message = baseExceptionInterface.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package com.jy.framework.common.response;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import com.jy.framework.common.exception.BaseExceptionInterface;
|
||||
import com.jy.framework.common.exception.BizException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title Response
|
||||
* @description 响应体
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -6624218097474846897L;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private boolean success = true;
|
||||
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success() {
|
||||
return new Response<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success(T data) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setData(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure() {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param code 异常码
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String code, String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(code);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param bizException 业务异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BizException bizException) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(bizException.getCode());
|
||||
response.setMessage(bizException.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param <T> 响应数据类型
|
||||
* @param baseExceptionInterface 基础异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BaseExceptionInterface baseExceptionInterface) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(baseExceptionInterface.getCode());
|
||||
response.setMessage(baseExceptionInterface.getMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.framework.common.utils;
|
||||
package com.jy.framework.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -8,10 +8,10 @@ import lombok.SneakyThrows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: JsonUtils
|
||||
* @Description: JSON 工具类
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/21
|
||||
* @author ayi
|
||||
* @title JsonUtils
|
||||
* @description JSON 工具类
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
public class JsonUtils {
|
||||
private static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package top.crushtj.framework.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: BaseExceptionInterface
|
||||
* @Description: 基础异常接口
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
public interface BaseExceptionInterface {
|
||||
/**
|
||||
* 获取异常码
|
||||
*
|
||||
* @return 异常码
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* 获取异常信息
|
||||
*
|
||||
* @return 异常信息
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package top.crushtj.framework.common.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: BusiException
|
||||
* @Description: 业务异常
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 异常码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param baseExceptionInterface 基础异常接口
|
||||
*/
|
||||
public BizException(BaseExceptionInterface baseExceptionInterface) {
|
||||
this.code = baseExceptionInterface.getCode();
|
||||
this.message = baseExceptionInterface.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package top.crushtj.framework.common.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import top.crushtj.framework.common.exception.BaseExceptionInterface;
|
||||
import top.crushtj.framework.common.exception.BizException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: Response
|
||||
* @Description: 响应体
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -6624218097474846897L;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private boolean success = true;
|
||||
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success() {
|
||||
return new Response<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success(T data) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setData(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure() {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param code 异常码
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String code, String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(code);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param bizException 业务异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BizException bizException) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(bizException.getCode());
|
||||
response.setMessage(bizException.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param <T>
|
||||
* @param baseExceptionInterface 基础异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BaseExceptionInterface baseExceptionInterface) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(baseExceptionInterface.getCode());
|
||||
response.setMessage(baseExceptionInterface.getMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,23 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>xiaoyi-spring-boot-starter-biz-operationlog</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>平台基础设施层:操作日志记录器</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-common</artifactId>
|
||||
</dependency>
|
||||
<!-- AOP 切面 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+14
-5
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.framework.biz.operationlog;
|
||||
package com.jy.framework.biz.operationlog;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@@ -12,15 +12,24 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import top.crushtj.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import top.crushtj.framework.common.utils.JsonUtils;
|
||||
import com.jy.framework.biz.operationlog.aspect.ApiOperationLog;
|
||||
import com.jy.framework.common.utils.JsonUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title ApiOperationLog
|
||||
* @description 自定义注解,用于标记需要记录操作日志的方法
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
public class ApiOperationLogAspect {
|
||||
/** 以自定义 @ApiOperationLog 注解为切点,凡是添加 @ApiOperationLog 的方法,都会执行环绕中的代码 */
|
||||
@Pointcut("@annotation(top.crushtj.framework.biz.operationlog.aspect.ApiOperationLog)")
|
||||
public void apiOperationLog() {}
|
||||
@Pointcut("@annotation(com.jy.framework.biz.operationlog.aspect.ApiOperationLog)")
|
||||
public void apiOperationLog() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 环绕
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.framework.biz.operationlog.aspect;
|
||||
package com.jy.framework.biz.operationlog.aspect;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -8,10 +8,10 @@ import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: ApiOperationLog
|
||||
* @Description: 自定义注解,用于标记需要记录操作日志的方法
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/21
|
||||
* @author ayi
|
||||
* @title ApiOperationLog
|
||||
* @description 自定义注解,用于标记需要记录操作日志的方法
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@@ -20,7 +20,7 @@ public @interface ApiOperationLog {
|
||||
/**
|
||||
* API 功能描述
|
||||
*
|
||||
* @return
|
||||
* @return 功能描述
|
||||
*/
|
||||
String description() default "";
|
||||
}
|
||||
+10
-2
@@ -1,9 +1,17 @@
|
||||
package top.crushtj.framework.biz.operationlog.config;
|
||||
package com.jy.framework.biz.operationlog.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import top.crushtj.framework.biz.operationlog.ApiOperationLogAspect;
|
||||
import com.jy.framework.biz.operationlog.ApiOperationLogAspect;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title ApiOperationLog
|
||||
* @description 自定义注解,用于标记需要记录操作日志的方法
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
|
||||
@AutoConfiguration
|
||||
public class ApiOperationLogAutoConfiguration {
|
||||
+1
-1
@@ -1 +1 @@
|
||||
top.crushtj.framework.biz.operationlog.config.ApiOperationLogAutoConfiguration
|
||||
com.jy.framework.biz.operationlog.config.ApiOperationLogAutoConfiguration
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>xiaoyi-spring-boot-starter-jackson</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>平台基础设施层:Jackson 配置</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+10
-8
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.xiaoyishu.auth.config;
|
||||
package com.jy.framework.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -12,10 +12,10 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.YearMonthSerializer;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import top.crushtj.framework.common.constant.DateConstants;
|
||||
import top.crushtj.framework.common.utils.JsonUtils;
|
||||
import com.jy.framework.common.constant.DateConstants;
|
||||
import com.jy.framework.common.utils.JsonUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -31,8 +31,8 @@ import java.util.TimeZone;
|
||||
* @date 2026/01/06
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
@AutoConfiguration
|
||||
public class JacksonAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
@@ -53,8 +53,10 @@ public class JacksonConfig {
|
||||
|
||||
// 支持 LocalDateTime、LocalDate、LocalTime
|
||||
// 支持 LocalDateTime、LocalDate、LocalTime
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateConstants.DATE_FORMAT_Y_M_D_H_M_S));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateConstants.DATE_FORMAT_Y_M_D_H_M_S));
|
||||
javaTimeModule.addSerializer(LocalDateTime.class,
|
||||
new LocalDateTimeSerializer(DateConstants.DATE_FORMAT_Y_M_D_H_M_S));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class,
|
||||
new LocalDateTimeDeserializer(DateConstants.DATE_FORMAT_Y_M_D_H_M_S));
|
||||
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateConstants.DATE_FORMAT_Y_M_D));
|
||||
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateConstants.DATE_FORMAT_Y_M_D));
|
||||
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateConstants.DATE_FORMAT_H_M_S));
|
||||
+1
@@ -0,0 +1 @@
|
||||
com.jy.framework.jackson.JacksonAutoConfiguration
|
||||
Reference in New Issue
Block a user