Kotlin idioms (#2534)

This commit is contained in:
Grzegorz Piwowarek 2017-08-31 15:03:02 +02:00 committed by GitHub
parent 49acba206c
commit d1a1322bcc
2 changed files with 12 additions and 21 deletions

View File

@ -12,13 +12,9 @@ import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver
import org.thymeleaf.spring4.view.ThymeleafViewResolver
import org.thymeleaf.templatemode.TemplateMode
@EnableWebMvc
@Configuration
open class ApplicationWebConfig: WebMvcConfigurerAdapter(), ApplicationContextAware {
open class ApplicationWebConfig : WebMvcConfigurerAdapter(), ApplicationContextAware {
private var applicationContext: ApplicationContext? = null
@ -34,27 +30,23 @@ open class ApplicationWebConfig: WebMvcConfigurerAdapter(), ApplicationContextAw
@Bean
open fun templateResolver(): SpringResourceTemplateResolver {
val templateResolver = SpringResourceTemplateResolver()
templateResolver.prefix = "/WEB-INF/view/"
templateResolver.suffix = ".html"
templateResolver.templateMode = TemplateMode.HTML
templateResolver.setApplicationContext(this.applicationContext);
return templateResolver
return SpringResourceTemplateResolver()
.apply { prefix = "/WEB-INF/view/" }
.apply { suffix = ".html"}
.apply { templateMode = TemplateMode.HTML }
.apply { setApplicationContext(applicationContext) }
}
@Bean
open fun templateEngine(): SpringTemplateEngine {
val templateEngine = SpringTemplateEngine()
templateEngine.setTemplateResolver(templateResolver())
return templateEngine
return SpringTemplateEngine()
.apply { setTemplateResolver(templateResolver()) }
}
@Bean
open fun viewResolver(): ThymeleafViewResolver {
val viewResolver = ThymeleafViewResolver()
viewResolver.templateEngine = templateEngine()
viewResolver.order = 1
return viewResolver
return ThymeleafViewResolver()
.apply { templateEngine = templateEngine() }
.apply { order = 1 }
}
}

View File

@ -1,9 +1,8 @@
package com.baeldung.kotlin.mvc
import com.baeldung.kotlin.mvc.ApplicationWebConfig
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
class ApplicationWebInitializer: AbstractAnnotationConfigDispatcherServletInitializer() {
class ApplicationWebInitializer : AbstractAnnotationConfigDispatcherServletInitializer() {
override fun getRootConfigClasses(): Array<Class<*>>? {
return null