1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package cn.gygxzc.envir.web.config
- import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
- import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration
- import org.springframework.context.annotation.Bean
- import org.springframework.context.annotation.Configuration
- import org.springframework.context.annotation.Import
- import org.springframework.context.annotation.Primary
- import org.springframework.http.converter.HttpMessageConverter
- import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
- import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
- import org.springframework.web.servlet.config.annotation.EnableWebMvc
- import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
- import java.text.SimpleDateFormat
- /**
- * Created by niantuo on 2018/9/20.
- *
- */
- @Configuration
- class EnvirWebMvcConfiguration : WebMvcConfigurer {
- companion object {
- const val CONVERTER_NAME = "hookMappingJackson2HttpMessageConverter"
- }
- override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
- registry.addResourceHandler("swagger-ui.html")
- .addResourceLocations("classpath:/META-INF/resources/")
- registry.addResourceHandler("/webjars*")
- .addResourceLocations("classpath:/META-INF/resources/webjars/")
- }
- override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
- converters.add(getConverter())
- }
- @Bean(CONVERTER_NAME)
- fun getConverter(): MappingJackson2HttpMessageConverter {
- return MappingJackson2HttpMessageConverter().apply {
- this.objectMapper = builder().build()
- }
- }
- @Bean
- @Primary
- fun builder(): Jackson2ObjectMapperBuilder {
- return Jackson2ObjectMapperBuilder().apply {
- serializerByType(java.lang.Long::class.java, ToStringSerializer.instance)
- serializerByType(java.lang.Long.TYPE, ToStringSerializer.instance)
- // date
- dateFormat(SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
- }
- }
- }
|