Skip to content

Commit

Permalink
增加mybatis枚举转换器
Browse files Browse the repository at this point in the history
  • Loading branch information
huaiyang committed Jan 13, 2020
1 parent 01cfa17 commit 522c6a3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class JacksonConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer customizer() {
return builder -> {
// mybatis 枚举序列化
builder.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
//为空的字段不返回
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
builder.locale(Locale.CHINA);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skrshop.earthsystem.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.skrshop.common.enums.BaseEnum;

/**
Expand All @@ -9,6 +10,7 @@ public enum AccountTypeEnum implements BaseEnum {
STAFF(0, "员工"),
USER(1, "用户");

@EnumValue//标记数据库存的值是code
private int code;
private String desc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public BaseResponse<AccountUserVo> createAccountUser(@RequestBody AccountUserDto
}

@Override
@GetMapping("/accountUserManagement/queryById")
public BaseResponse<AccountUserVo> queryById(@RequestParam Long id) {
@GetMapping(path = "/accountUserManagement/queryById")
public BaseResponse<AccountUserVo> queryById(@RequestParam Long id) {
return BaseResponse.code().data(accountUserService.queryById(id)).build();
}
}
2 changes: 1 addition & 1 deletion earthsystem/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ server:
context-path: /skrshop/earthsystem
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
typeEnumsPackage: com.skrshop.skrshoptkmybatis.handler
typeEnumsPackage: com.skrshop.skrshoptkmybatis.handler

feign:
client:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.skrshop.skrshoptkmybatis.Performance;

import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.ibatis.plugin.Interceptor;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
Expand Down

0 comments on commit 522c6a3

Please sign in to comment.