springboot2.x 返回前端数据类型自动转换

框架:spring2.x
描述:将返回前端数据中long类型的数据组自动转换为String

@Configuration
public class WebConfiguration  {
    /**
     * 前后端交互,属性Long转换为String
     */
    @Bean
    public HttpMessageConverters customConverters() {
        FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fjc = new FastJsonConfig();
        SerializeConfig serializeConfig = SerializeConfig.globalInstance;
        serializeConfig.put(Long.class , ToStringSerializer.instance);
        serializeConfig.put(Long.TYPE , ToStringSerializer.instance);
        fjc.setSerializeConfig(serializeConfig);
        fastJsonConverter.setFastJsonConfig(fjc);
        return new HttpMessageConverters(fastJsonConverter);
    }
}

你可能感兴趣的:(java,springboot,数据类型转换)