¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.module.SimpleModule; |
| | | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
| | | |
| | | /** |
| | | * å½Mybatis plus设置为éªè±IDæ¶ |
| | | * ä½¿ç¨æ¤ç±»ï¼ä¼ææææ°åè¿åå为å符串è¿åéé
å端Longå失çé®é¢ |
| | | * |
| | | * @author Ming LI |
| | | */ |
| | | @Configuration |
| | | public class JacksonConfig { |
| | | |
| | | @Bean |
| | | @Primary |
| | | @ConditionalOnMissingBean(ObjectMapper.class) |
| | | @ConditionalOnProperty(value = "mybatis-plus.global-config.dbConfig.idType", havingValue = "ASSIGN_ID") |
| | | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { |
| | | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); |
| | | // å
¨å±é
ç½®åºååè¿å JSON å¤ç |
| | | SimpleModule simpleModule = new SimpleModule(); |
| | | //JSON Long ==> String |
| | | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
| | | objectMapper.registerModule(simpleModule); |
| | | return objectMapper; |
| | | } |
| | | |
| | | } |