Ver código fonte

推荐信息接口格式同步

调整日期格式出参入参
tags/24080901
niohe·erbao 1 ano atrás
pai
commit
53c0caacab
3 arquivos alterados com 45 adições e 40 exclusões
  1. +42
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java
  2. +0
    -34
      pmapi/src/main/java/com/ningdatech/pmapi/common/config/JacksonConfig.java
  3. +3
    -6
      pmapi/src/main/java/com/ningdatech/pmapi/common/model/FileBasicInfo.java

+ 42
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java Ver arquivo

@@ -0,0 +1,42 @@
package com.ningdatech.pmapi.common.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* @author qinxianyun
*/
@EnableWebMvc
@Configuration
public class ConfigurerAdapter implements WebMvcConfigurer {

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
// 使用 fastjson 序列化,会导致 @JsonIgnore 失效,可以使用 @JSONField(serialize = false) 替换
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
List<MediaType> supportMediaTypeList = new ArrayList<>();
supportMediaTypeList.add(MediaType.APPLICATION_JSON);
FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
converter.setFastJsonConfig(config);
converter.setSupportedMediaTypes(supportMediaTypeList);
converter.setDefaultCharset(StandardCharsets.UTF_8);
converters.add(converter);
}
}

+ 0
- 34
pmapi/src/main/java/com/ningdatech/pmapi/common/config/JacksonConfig.java Ver arquivo

@@ -1,34 +0,0 @@
package com.ningdatech.pmapi.common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* @author liuxinxin
* @date 2023/3/9 下午1:50
*/
@Configuration
public class JacksonConfig {
@Value("${spring.jackson.local-date-time-format:yyyy-MM-dd HH:mm:ss}")
String localDateTimeFormat;


@Bean
public ObjectMapper objectMapper() {
ObjectMapper om = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDateTime.class,
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(localDateTimeFormat)));
javaTimeModule.addDeserializer(LocalDateTime.class,
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(localDateTimeFormat)));
return om;
}
}

+ 3
- 6
pmapi/src/main/java/com/ningdatech/pmapi/common/model/FileBasicInfo.java Ver arquivo

@@ -16,12 +16,9 @@ public class FileBasicInfo {
@ApiModelProperty("文件id")
private Long fileId;

@ApiModelProperty("文件url")
private String url;

@ApiModelProperty("文件名")
private String fileName;

@ApiModelProperty("文件类型")
private Integer fileType;

@ApiModelProperty("文件路径")
private String filePath;
}

Carregando…
Cancelar
Salvar