|
@@ -0,0 +1,63 @@
|
|
|
+package cn.tonyandmoney.tuon.core.config
|
|
|
+
|
|
|
+import cn.tonyandmoney.tuon.core.properties.CustomConfigProperties
|
|
|
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
|
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|
|
+import org.springframework.context.annotation.Bean
|
|
|
+import org.springframework.context.annotation.Configuration
|
|
|
+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.ResourceHandlerRegistry
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
|
|
+import java.text.SimpleDateFormat
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by niantuo on 2018/9/20.
|
|
|
+ * mvc 配置
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableConfigurationProperties(CustomConfigProperties::class)
|
|
|
+@ConditionalOnProperty(prefix = "custom.config.enable.web", havingValue = "true", matchIfMissing = true)
|
|
|
+class CustomWebMvcConfiguration : 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"))
|
|
|
+ timeZone("GMT+8")
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|