Commit bd6fdd29 authored by 技术部-任文超's avatar 技术部-任文超

Merge branch 'convert'

parents 9ad3153e d086ffb2
......@@ -66,10 +66,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
......
......@@ -30,6 +30,8 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.filter.CharacterEncodingFilter;
......@@ -78,20 +80,24 @@ public class HttpConfig {
return builder;
}
// hack spring mvc.
@Bean
public IntegerToEnumConverterFactory getIntegerToEnumConverterFactory(
ConverterRegistry defaultConversionService, ConverterRegistry mvcConversionService, ConverterRegistry integrationConversionService) {
IntegerToEnumConverterFactory factory = new IntegerToEnumConverterFactory();
public ConverterRegistry defaultConversionService() {
FormattingConversionService conversionService = new DefaultFormattingConversionService();
addFormatters(conversionService);
return conversionService;
}
@Bean
public ConverterRegistry integrationConversionService() {
FormattingConversionService conversionService = new DefaultFormattingConversionService();
addFormatters(conversionService);
return conversionService;
}
defaultConversionService.removeConvertible(String.class, Enum.class);
mvcConversionService.removeConvertible(String.class, Enum.class);
integrationConversionService.removeConvertible(String.class, Enum.class);
defaultConversionService.addConverterFactory(factory);
mvcConversionService.addConverterFactory(factory);
integrationConversionService.addConverterFactory(factory);
return factory;
private void addFormatters(FormattingConversionService conversionService) {
IntegerToEnumConverterFactory factory = new IntegerToEnumConverterFactory();
conversionService.removeConvertible(String.class,Enum.class);
conversionService.addConverterFactory(factory);
}
@Bean(name = "httpClient")
......
package cn.quantgroup.xyqb.config.http;
import org.springframework.format.FormatterRegistry;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Component
public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.removeConvertible(String.class,Enum.class);
registry.addConverterFactory(new IntegerToEnumConverterFactory());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment