Skip to content

Commit 493f10e

Browse files
committed
Change configuration method
1 parent 1baf6dc commit 493f10e

File tree

10 files changed

+558
-421
lines changed

10 files changed

+558
-421
lines changed

src/main/asciidoc/user-guide.adoc

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ templateEngine.setEngineContextFactory(new MyBatisIntegratingEngineContextFactor
464464
// ...
465465
466466
Configuration configuration = new Configuration();
467-
configuration.getLanguageRegistry()
468-
.register(ThymeleafLanguageDriver.newBuilder().templateEngine(templateEngine).build()); // <2>
467+
configuration.getLanguageRegistry().register(new ThymeleafLanguageDriver(templateEngine)); // <2>
469468
configuration.setDefaultScriptingLanguage(ThymeleafLanguageDriver.class); // <3>
470469
----
471470

@@ -1079,14 +1078,14 @@ use-2way = false # <1>
10791078
or
10801079

10811080
[source,java]
1082-
.How to configure using builder option
1081+
.How to configure using config class
10831082
----
1084-
configuration.getLanguageRegistry()
1085-
.register(ThymeleafLanguageDriver.newBuilder().use2way(false).build()); // <2>
1083+
configuration.getLanguageRegistry().register(new ThymeleafLanguageDriver(
1084+
ThymeleafLanguageDriverConfig.newInstance(c -> c.setUse2Way(false)))); // <2>
10861085
----
10871086

10881087
<1> Set the `use-2way` to `false`
1089-
<2> Set the `use2way` builder option to `false`
1088+
<2> Set the `use2way` property to `false`
10901089

10911090

10921091
=== Basic usage
@@ -1142,8 +1141,7 @@ ConfigurationCustomizer mybatisConfigurationCustomizer() {
11421141
templateEngine.setEngineContextFactory(new MyBatisIntegratingEngineContextFactory(
11431142
targetTemplateEngine.getEngineContextFactory()));
11441143
// ...
1145-
configuration.getLanguageRegistry().register(
1146-
ThymeleafLanguageDriver.newBuilder().templateEngine(templateEngine).build()); // <2>
1144+
configuration.getLanguageRegistry().register(new ThymeleafLanguageDriver(templateEngine)); // <2>
11471145
configuration.setDefaultScriptingLanguage(ThymeleafLanguageDriver.class); // <3>
11481146
};
11491147
}
@@ -1163,7 +1161,7 @@ ConfigurationCustomizer mybatisConfigurationCustomizer() {
11631161

11641162
The mybatis-thymeleaf provides following properties for customizing configurations.
11651163

1166-
[cols="1,6,^1,2",options="header"]
1164+
[cols="3,4,^1,2",options="header"]
11671165
.Supported property list
11681166
|===
11691167
^|Property Key
@@ -1184,31 +1182,30 @@ The mybatis-thymeleaf provides following properties for customizing configuratio
11841182
|`Class`
11851183
|`null` (This instance is do-nothing)
11861184

1187-
4+|*Template cache configuration*
1185+
4+|*Template file configuration*
1186+
11881187

1189-
|`cache.enabled`
1188+
|`template-file.cache-enabled`
11901189
|Whether use the cache feature when load template resource file
11911190
|`Boolean`
11921191
|`true` (enable template cache feature)
11931192

1194-
|`cache.ttl`
1193+
|`template-file.cache-ttl`
11951194
|The cache TTL(millisecond) for resolved templates
11961195
|`Long`
11971196
|`null` (no TTL)
11981197

1199-
4+|*Template file configuration*
1200-
1201-
|`file.character-encoding`
1198+
|`template-file.encoding`
12021199
|The character encoding for reading template resource file
12031200
|`String`
12041201
|`"UTF-8"`
12051202

1206-
|`file.base-dir`
1203+
|`template-file.base-dir`
12071204
|The base directory for reading template resource file
12081205
|`String`
12091206
|`""` (just under class path)
12101207

1211-
|`file.patterns`
1208+
|`template-file.patterns`
12121209
|The patterns for reading as template resource file
12131210
(Can specify multiple patterns using comma(`","`) as separator character)
12141211
|`String`
@@ -1221,18 +1218,18 @@ The mybatis-thymeleaf provides following properties for customizing configuratio
12211218
|`String`
12221219
|`"mb"`
12231220

1224-
|`dialect.like.escape-char`
1221+
|`dialect.like-escape-char`
12251222
|The escape character for wildcard of LIKE condition
12261223
|`Character`
12271224
|`'\'` (backslash)
12281225

1229-
|`dialect.like.escape-clause-format`
1226+
|`dialect.like-escape-clause-format`
12301227
|The format of escape clause for LIKE condition
12311228
(Can specify format that can be allowed by `String#format` method)
12321229
|`String`
12331230
|`"ESCAPE '%s'"`
12341231

1235-
|`dialect.like.additional-escape-target-chars`
1232+
|`dialect.like-additional-escape-target-chars`
12361233
|Additional escape target characters(custom wildcard characters) for LIKE condition
12371234
(Can specify multiple characters using comma(`","`) as separator character)
12381235
|`String`
@@ -1244,40 +1241,47 @@ The mybatis-thymeleaf provides following properties for customizing configuratio
12441241
----
12451242
use-2way = true
12461243
customizer = com.example.MyTemplateEngineCustomizer
1247-
cache.enabled = true
1248-
cache.ttl = 3600000
1249-
file.character-encoding = UTF-8
1250-
file.base-dir = /templates/sqls
1251-
file.patterns = *sql, *.sql.template
1244+
template-file.cache-enabled = true
1245+
template-file.cache-ttl = 3600000
1246+
template-file.encoding = UTF-8
1247+
template-file.base-dir = /templates/sqls
1248+
template-file.patterns = *sql, *.sql.template
12521249
dialect.prefix = mybatis
1253-
dialect.like.escape-char = ~
1254-
dialect.like.escape-clause-format = escape '%s'
1255-
dialect.like.additional-escape-target-chars = %, _
1250+
dialect.like-escape-char = ~
1251+
dialect.like-escape-clause-format = escape '%s'
1252+
dialect.like-additional-escape-target-chars = %, _
12561253
----
12571254

12581255
[TIP]
12591256
====
1260-
These properties can be specified via builder class of `ThymeleafLanguageDriver` as follow:
1257+
These properties can be specified via factory method of `ThymeleafLanguageDriverConfig` as follow:
12611258
12621259
[source,java]
12631260
----
1264-
configuration.getLanguageRegistry().register(ThymeleafLanguageDriver.newBuilder()
1265-
.use2way(true)
1266-
.customizer(CustomTemplateEngineCustomizer.class)
1267-
.cacheEnabled(true)
1268-
.cacheTtl(3600000)
1269-
.fileCharacterEncoding(StandardCharsets.UTF_8)
1270-
.fileBaseDir("/templates/sqls")
1271-
.filePatterns("*.sql", "*.sql.template")
1272-
.dialectPrefix("mybatis")
1273-
.dialectLikeEscapeChar('~')
1274-
.dialectLikeEscapeClauseFormat("escape '%s'")
1275-
.dialectLikeAdditionalEscapeTargetChars('%' , '_')
1276-
.customProperties(configurationProperties)
1277-
.build());
1278-
----
1279-
1280-
If you specify the value both with properties file and builder option, the properties file value applied.
1261+
configuration.getLanguageRegistry().register(
1262+
new ThymeleafLanguageDriver(ThymeleafLanguageDriverConfig.newInstance(c -> {
1263+
c.setUse2way(true);
1264+
c.setCustomizer(CustomTemplateEngineCustomizer.class);
1265+
c.getTemplateFile().setCacheEnabled(false);
1266+
c.getTemplateFile().setCacheTtl(3600000L);
1267+
c.getTemplateFile().setEncoding(StandardCharsets.UTF_8);
1268+
c.getTemplateFile().setBaseDir("/templates/sqls/");
1269+
c.getTemplateFile().setPatterns("*.sql", "*.sql.template");
1270+
c.getDialect().setPrefix("mybatis");
1271+
c.getDialect().setLikeEscapeChar('~');
1272+
c.getDialect().setLikeEscapeClauseFormat("escape '%s'");
1273+
c.getDialect().setLikeAdditionalEscapeTargetChars('%', '_');
1274+
})));
1275+
----
1276+
1277+
If you specify the value both with properties file and customizer function, the properties file value applied.
1278+
We provide following factory methods for creating a `ThymeleafLanguageDriver` instance.
1279+
1280+
* `newInstance()`
1281+
* `newInstance(String resourcePath)`
1282+
* `newInstance(Properties customProperteis)`
1283+
* `newInstance(Consumer<ThymeleafLanguageDriverConfig> customizer)`
1284+
12811285
====
12821286

12831287

src/main/java/org/mybatis/scripting/thymeleaf/TemplateEngineCustomizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* <br>
2727
* If you want to customize a default {@code TemplateEngine},
2828
* you implements class of this interface and you need to specify
29-
* the 'template.customizer' property of mybatis-thymeleaf.properties.
29+
* the 'customizer' property of mybatis-thymeleaf.properties.
3030
* <br>
3131
* e.g.) Implementation class:
3232
* <pre>
@@ -51,6 +51,7 @@ public interface TemplateEngineCustomizer extends Consumer<TemplateEngine> {
5151

5252
/**
5353
* {@inheritDoc}
54+
* @see #customize(TemplateEngine)
5455
*/
5556
@Override
5657
default void accept(TemplateEngine templateEngine) {

0 commit comments

Comments
 (0)