Skip to content

Commit e73a5d0

Browse files
committed
Polishing user's guide
1 parent 87f581a commit e73a5d0

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed

src/main/asciidoc/user-guide.adoc

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
:travis-ci-url: https://travis-ci.org/mybatis/thymeleaf-scripting
2222
:thymeleaf-doc-url: https://www.thymeleaf.org/doc/tutorials/3.0
2323
:github-organization-url: https://github.com/mybatis
24+
:github-url: {github-organization-url}/thymeleaf-scripting
25+
:github-wiki-url: {github-url}/wiki
2426

2527
// Define dependency artifact versions
2628
:mybatis-version: y.y.y
@@ -30,7 +32,7 @@
3032
=== What is MyBatis Thymeleaf ?
3133

3234
The mybatis-thymeleaf is a plugin that helps applying the 2-way SQL/dynamic SQL feature to the MyBatis 3
33-
using the template(or natural template) mechanism provided by Thymeleaf 3.
35+
using the template mechanism provided by Thymeleaf 3.
3436
If you are not familiar with MyBatis and Thymeleaf, you can see following official documentations.
3537

3638
* {mybatis-doc-url}[MyBatis 3 REFERENCE DOCUMENTATION^]
@@ -42,15 +44,15 @@ If you are not familiar with MyBatis and Thymeleaf, you can see following offici
4244
The 2-way SQL can be used by following *two way*.
4345

4446
* It can be executed as-is in SQL execution tool (such as psql, mysql, sqlplus, plugins for IDE, etc...)
45-
* It can be used as a SQL template for creating a bindable and dynamically SQL on your application
47+
* It can be used as a SQL template for creating a bindable and dynamically SQL that can be parsed by MyBatis core module
4648

4749
==== Simple bindable 2-way SQL
4850

49-
The mybatis-thymeleaf translate a simple bindable 2-way SQL that specified by natural template to as follow:
51+
The mybatis-thymeleaf support a simple bindable 2-way SQL as follow:
5052

5153

5254
[source,sql]
53-
.SQL Template using custom attribute tag provided by mybatis-thymeleaf
55+
.SQL Template
5456
----
5557
SELECT * FROM names
5658
WHERE id = /*[# mb:p="id"]*/ 1 /*[/]*/
@@ -59,10 +61,10 @@ SELECT * FROM names
5961

6062
==== Dynamically bindable 2-way SQL
6163

62-
The mybatis-thymeleaf translate a dynamically bindable 2-way SQL that specified by natural template to as follow:
64+
The mybatis-thymeleaf support a dynamically bindable 2-way SQL as follow:
6365

6466
[source,sql]
65-
.SQL Template using custom attribute tag provided by mybatis-thymeleaf
67+
.SQL Template
6668
----
6769
SELECT * FROM names
6870
WHERE 1 = 1
@@ -74,10 +76,10 @@ SELECT * FROM names
7476

7577
==== Dynamically bindable SQL
7678

77-
The mybatis-thymeleaf translate a dynamically bindable SQL(non 2-way SQL) that specified by template to as follow:
79+
The mybatis-thymeleaf support a dynamically bindable SQL(non 2-way SQL) as follow:
7880

7981
[source,sql]
80-
.SQL Template using custom attribute tag provided by mybatis-thymeleaf
82+
.SQL Template
8183
----
8284
SELECT * FROM names
8385
WHERE 1 = 1
@@ -96,8 +98,8 @@ for integrating with template engine provide by Thymeleaf.
9698

9799
* Can write 2-way SQL/dynamic SQL
98100
* Can use a 2-way SQL/dynamic SQL via an annotation and mapper xml
99-
* Can read an SQL template from a template file on classpath
100-
* Can use a custom dialect(attribute tag and expression utility method) at a template
101+
* Can read an SQL template from a Thymeleaf template file on classpath
102+
* Can use a custom dialect(attribute tag and expression utility method) on your SQL template
101103
* Can fully customize a template engine configuration
102104

103105

@@ -456,7 +458,7 @@ SELECT * FROM names
456458
----
457459

458460
[source,sql]
459-
.2-way SQL template for generating string that can be parsed by MyBatis core module
461+
.SQL template for generating string that can be parsed by MyBatis core module
460462
----
461463
SELECT * FROM names
462464
WHERE id = /*[# mb:p="id"]*/ 1 /*[/]*/ -- <2>
@@ -477,7 +479,7 @@ About usage of `mb:bind`, please see <<Attribute tag>>.
477479
=== Dynamic SQL
478480

479481
The Thymeleaf supports to create an any string dynamically using conditional evaluation
480-
and iterating evaluation feature. By using this feature, you can write a dynamic 2-way SQL.
482+
and iterating evaluation feature. By using this feature, you can write a dynamic SQL.
481483

482484
* <<Using tag for specifying condition>>
483485
* <<Using tag for iteration>>
@@ -545,21 +547,21 @@ SELECT * FROM names
545547

546548
<1> Specify an iterable object on `th:each`
547549

548-
<2> Specify a 2-way SQL of binding value per iterable element.
549-
A bind value specify by `mb:p="{variable name of iterable element}"` format.
550+
<2> Specify a SQL template of binding value per iterable element.
551+
A bind value specify by `mb:p="{variable name of iterable element}"` format (e.g. `id`).
550552

551553
<3> Append comma character when element position is not last.
552-
You can access an iteration status object (`IterationStatusVar`) that named by `"{variable name of iterable element}Stat"` format.
554+
You can access an iteration status object (`IterationStatusVar`) that named by `"{variable name of iterable element}Stat"` format (e.g. `idStat`).
553555

554556
<4> Specify an end tag of iteration
555557

556558
[TIP]
557559
====
558-
Also, an above SQL template can be replaced using `mb:p` attribute tag with following SQL template.
560+
An above SQL template can be replaced using `mb:p` attribute tag with following SQL template.
559561
560562
561563
[source,sql]
562-
.Use `mb:p` for creating bind variables string of IN clause
564+
.Use mb:p for creating bind variables string of IN clause
563565
----
564566
SELECT * FROM names
565567
WHERE 1 = 1
@@ -570,17 +572,17 @@ SELECT * FROM names
570572
----
571573
====
572574

573-
About more advanced usage, please see <<Bulk insert>>.
575+
About more advanced usage of `th:each` , please see <<Bulk insert>>.
574576

575577
=== Fragment
576578

577579
The Thymeleaf supports to insert template string from an another template file.
578-
By using this feature, you can share a 2-way SQL on multiple SQL template.
580+
By using this feature, you can share an SQL on multiple SQL template.
579581

580582
The standard use case using this feature is paging query as follow:
581583

582584
[source,java]
583-
.Mapper
585+
.Mapper interface
584586
----
585587
// Count a total record number that matches for criteria
586588
@Select("/NameMapper/countByCriteria.sql")
@@ -670,7 +672,7 @@ SELECT * FROM names
670672

671673
=== Special variables
672674

673-
The mybatis and mybatis-thymeleaf provides special variables that prefixed with `_` as follows:
675+
The MyBatis core module provides special variables that prefixed with `_` as follows:
674676

675677
[cols="2,7,1",options="header"]
676678
.Special variables
@@ -684,7 +686,7 @@ The mybatis and mybatis-thymeleaf provides special variables that prefixed with
684686
|Any type
685687

686688
|`_databaseId`
687-
|The id for identifying the database
689+
|The id for identifying the database on current session
688690
(If you want to this variable, you should be enabled the link:{mybatis-doc-url}/configuration.html#databaseIdProvider[`DatabaseIdProvider` feature^] on MyBatis)
689691
|`String`
690692
|===
@@ -695,7 +697,7 @@ You can access the configuration properties of MyBatis from your SQL template.
695697
About configuration properties, please see the link:{mybatis-doc-url}/configuration.html#properties[MyBatis reference documentation^].
696698

697699
[source,java]
698-
.Java based configuration
700+
.How to set configuration properties using Java based configuration
699701
----
700702
Configuration configuration = new Configuration();
701703
Properties variables = new Properties();
@@ -704,7 +706,7 @@ configuration.setVariables(variables);
704706
----
705707

706708
[source,xml]
707-
.XML based configuration (mybatis-config.xml)
709+
.How to set configuration properties using XML based configuration (mybatis-config.xml)
708710
----
709711
<properties>
710712
<property name="tableNameOfUser" value="accounts"/> <!--1-->
@@ -723,13 +725,13 @@ SELECT * FROM /*[(${tableNameOfUser} ?: 'users')]*/ users -- <2>
723725
Above SQL template translate to as follows:
724726

725727
[source,sql]
726-
.Translated SQL (when `tableNameOfUser` is defined)
728+
.Translated SQL (when tableNameOfUser is defined)
727729
----
728730
SELECT * FROM accounts
729731
----
730732

731733
[source,sql]
732-
.Translated SQL (when `tableNameOfUser` is not defined)
734+
.Translated SQL (when tableNameOfUser is not defined)
733735
----
734736
SELECT * FROM users
735737
----
@@ -787,10 +789,11 @@ SELECT * FROM names
787789
== Custom Dialect
788790

789791
The mybatis-thymeleaf provide the custom dialect class(`org.mybatis.scripting.thymeleaf.MyBatisDialect`)
790-
that help for generating dynamic SQL.
792+
that help for generating SQL template.
791793

792794
=== Attribute tag
793795

796+
The mybatis-thymeleaf provides following attribute tags.
794797
By default, you can use it using `mb` dialect prefix (default prefix is initial letter of "**M**y**B**atis").
795798

796799
[cols="2,4,4",options="header"]
@@ -801,7 +804,7 @@ By default, you can use it using `mb` dialect prefix (default prefix is initial
801804
^|Attribute Value Format
802805

803806
|<<mybatis-param,p>>
804-
a|Render bind variable(`#{...}`) that can parsed MyBatis and register an iteration object to the MyBatis's bind variables.
807+
a|Render bind variable(`#{...}`) that can be parsed by MyBatis core module and register an iteration object to the MyBatis's bind variables.
805808
a|`{variableName}(,{optionKey}={optionValue},...)` +
806809
+
807810
Valid format is same with link:{mybatis-doc-url}/sqlmap-xml.html#Parameters[MyBatis's inline parameter format^].
@@ -838,9 +841,9 @@ SELECT * FROM names
838841
WHERE id IN (/*[# mb:p="ids"]*/ 1 /*[/]*/) -- <3>
839842
----
840843

841-
<1> Render single bind variable(e.g. `#{id}`) that can parsed MyBatis when specify a simple value object
844+
<1> Render single bind variable(e.g. `#{id}`) that can be parsed by MyBatis core module when specify a simple value object
842845
<2> Can specify parameter options(`key=value` format) separate with comma
843-
<3> Render multiple bind variables(e.g. `#{ids[0]}, #{ids[1]}, ...`) that can parsed MyBatis when specify a collection or array object
846+
<3> Render multiple bind variables(e.g. `#{ids[0]}, #{ids[1]}, ...`) that can be parsed by MyBatis core module when specify a collection or array object
844847

845848

846849
[[mybatis-bind]]
@@ -902,13 +905,13 @@ The `#likes` expression provide utility methods for LIKE clause.
902905
!A target value
903906
!===
904907

905-
|Return a value that escaped a wildcard character of LIKE condition
906-
(By default behavior, this method escape the `"%"`, `"_"` and `"\"`(escape character itself) using `"\"`)
908+
|Return a value that escaped a wildcard character of LIKE condition.
909+
By default behavior, this method escape the `"%"`, `"_"` and `"\"`(escape character itself) using `"\"`.
907910

908911
|<<mybatis-likeEscapeClause,escapeClause>>
909-
| N/A
910-
|Return a escape clause string of LIKE condition
911-
( By default behavior, this method return `"ESCAPE '\'"`)
912+
| None
913+
|Return a escape clause string of LIKE condition.
914+
By default behavior, this method return `"ESCAPE '\'"`.
912915
|===
913916

914917

@@ -1247,3 +1250,25 @@ fun findById(id: Int): Name
12471250
Todo findById(int id);
12481251
----
12491252

1253+
=== Related resources
1254+
1255+
1256+
[cols="2,8",options="header"]
1257+
.Related resource list
1258+
|===
1259+
^|Resource name
1260+
^|Description
1261+
1262+
|link:{github-url}[GiHub Page^]
1263+
|The mybatis-thymeleaf GiHub top page
1264+
1265+
|link:{github-wiki-url}/Usage-on-framework[Usage on framework^]
1266+
|Explain how to integrate with an application framework
1267+
1268+
|link:{github-wiki-url}/Code-completion[Code completion^]
1269+
|Explain about code completion
1270+
1271+
|link:{github-wiki-url}/Quick-Start[Quick Start^]
1272+
|Explain how to use mybatis-thymeleaf quickly using the Spring Boot
1273+
|===
1274+

0 commit comments

Comments
 (0)