2、自定义Jackson starter
This commit is contained in:
+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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package top.crushtj.xiaoyishu.auth.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import top.crushtj.framework.common.constant.DateConstants;
|
||||
import top.crushtj.framework.common.utils.JsonUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.YearMonth;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author ayi
|
||||
* @version V1.0
|
||||
* @title JacksonConfig
|
||||
* @description jackson 配置类
|
||||
* @date 2026/01/06
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 忽略未知属性
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
|
||||
// 设置凡是为 null 的字段,返参中均不返回,请根据项目组约定是否开启
|
||||
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
// 设置时区
|
||||
objectMapper.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
|
||||
// JavaTimeModule 用于指定序列化和反序列化规则
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
|
||||
// 支持 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(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));
|
||||
javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateConstants.DATE_FORMAT_H_M_S));
|
||||
// 支持 YearMonth
|
||||
javaTimeModule.addSerializer(YearMonth.class, new YearMonthSerializer(DateConstants.DATE_FORMAT_Y_M));
|
||||
javaTimeModule.addDeserializer(YearMonth.class, new YearMonthDeserializer(DateConstants.DATE_FORMAT_Y_M));
|
||||
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
|
||||
JsonUtils.init(objectMapper);
|
||||
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
+15
-9
@@ -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())
|
||||
.build();
|
||||
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);
|
||||
Reference in New Issue
Block a user