- Notifications
You must be signed in to change notification settings - Fork6
Usage on framework
In this page, we explain ways that integrate with an application framework.
The mybatis-spring-boot-starter 2.1 will supports spring-boot 2.1, 2.2, 2.3 and 2.4.
The mybatis-spring-boot-starter 2.2 will supports spring-boot 2.2, 2.5+.
Since the mybatis-spring-boot-starter 2.1+,it support the auto-configure for language driver. Therefore you can enable the this plugin on your application simply by adding this artifact under classpath. Furthermore if theLanguageDriver
bean’s count is one, the auto-configure set to default scripting language driver.
You can customize a configuration usingmybatis-thymeleaf.properties
. Furthermore since the mybatis-spring-boot-starter 2.1+,it support the configuration properties that prefixedmybatis.scripting-language-driver.thymeleaf
for customizing this plugin feature as follow:
mybatis.scripting-language-driver.thymeleaf.use2way = falsemybatis.scripting-language-driver.thymeleaf.template-file.cache-ttl = 3600000
mybatis:scripting-language-driver:thymeleaf:use2way:falsetemplate-file:cache-ttl:3600000
For more information on configurable properties, please refer tothe reference documentation.
Also, you can fully customize a template engine by adding theThymeleafLanguageDriver
instance to the DI container using@Bean
method.
@BeanThymeleafLanguageDriverthymeleafLanguageDriver() {TemplateEnginetemplateEngine =newTemplateEngine();// (1)templateEngine.addDialect(newMyBatisDialect());templateEngine.setEngineContextFactory(newMyBatisIntegratingEngineContextFactory(templateEngine.getEngineContextFactory()));// ...returnnewThymeleafLanguageDriver(templateEngine);// (2)}
Create an instance of class that implements
org.thymeleaf.ITemplateEngine
Create and return an instance of
ThymeleafLanguageDriver
that associate with user-defined template engine instance
The mybatis-spring-boot-starter 2.0 supports spring-boot 2.0 and 2.1.
If you are using themybatis-spring-boot-starter(Spring Boot),you can configure using configuration properties(properties or yaml file) as follow:
mybatis.configuration.default-scripting-language=org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver# Workaround for https://github.com/spring-projects/spring-boot/issues/16079# Adding if need (If you use the Spring Boot 2.1.4+, this configuration not need)spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
mybatis:configuration:default-scripting-language:org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver# Workaround for https://github.com/spring-projects/spring-boot/issues/16079# Adding if need (If you use the Spring Boot 2.1.4+, this configuration not need)spring:autoconfigure:exclude:org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
You can customize a configuration usingmybatis-thymeleaf.properties
.Furthermore, you can customize using the Spring Boot configuration properties instead ofmybatis-thymeleaf.properties
as follow:
mybatis.configuration-properties.use-2way=false# (1)mybatis.configuration-properties.template-file.cache-ttl=3600000
mybatis:configuration-properties:use-2way:false# (1)template-file.cache-ttl:3600000
@BeanConfigurationCustomizermybatisConfigurationCustomizer(MyBatisPropertiesproperties) {returnconfiguration -> {configuration.getLanguageRegistry().register(newThymeleafLanguageDriver(ThymeleafLanguageDriverConfig.newInstance(properties.getConfigurationProperties())));// (2)configuration.setDefaultScriptingLanguage(ThymeleafLanguageDriver.class);// (3) };}
Specify the configuration property of
mybatis.configuration.configuration-properties.{property key}
formatCreate a
ThymeleafLanguageDriverConfig
instance usingProperties
object that holds values ofmybatis.configuration.configuration-properties.{property key}
andregister aThymeleafLanguageDriver
correspond with it.Set the
ThymeleafLanguageDriver
class as default scripting language driverat after registering aThymeleafLanguageDriver
instance instead of Spring Boot configuration properties (Very Important!!)
For more information on configurable properties, please refer tothe reference documentation.
Also, you can fully customize a template engine using theConfigurationCustomizer
.
@BeanConfigurationCustomizermybatisConfigurationCustomizer() {returnconfiguration -> {TemplateEnginetemplateEngine =newTemplateEngine();// (1)templateEngine.addDialect(newMyBatisDialect());templateEngine.setEngineContextFactory(newMyBatisIntegratingEngineContextFactory(templateEngine.getEngineContextFactory()));// ...configuration.getLanguageRegistry().register(newThymeleafLanguageDriver(templateEngine));// (2)configuration.setDefaultScriptingLanguage(ThymeleafLanguageDriver.class);// (3) };}
Create an instance of class that implements
org.thymeleaf.ITemplateEngine
Register an instance of
ThymeleafLanguageDriver
that associate with user-defined template engine instanceSet the
ThymeleafLanguageDriver
class as default scripting language driver at after registering aThymeleafLanguageDriver
instance instead of Spring Boot configuration properties (Very Important!!)