Skip to content

Commit 5368948

Browse files
docs: refactor in markdown
1 parent 44a5a1e commit 5368948

File tree

8 files changed

+2576
-317
lines changed

8 files changed

+2576
-317
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@
419419
</configuration>
420420
</execution>
421421
</executions>
422+
<configuration>
423+
<escapeString>\</escapeString>
424+
</configuration>
422425
</plugin>
423426
<plugin>
424427
<groupId>org.apache.maven.plugins</groupId>

src/site/markdown/configuration.md

Lines changed: 1283 additions & 133 deletions
Large diffs are not rendered by default.

src/site/markdown/dynamic-sql.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ The Dynamic SQL elements should be familiar to anyone who has used JSTL or any s
1111
- trim (where, set)
1212
- foreach
1313

14-
15-
1614
### if
1715

1816
The most common thing to do in dynamic SQL is conditionally include a part of a where clause. For example:
1917

20-
```
18+
```xml
2119
<select id="findActiveBlogWithTitleLike"
2220
resultType="Blog">
2321
SELECT * FROM BLOG
@@ -69,8 +67,6 @@ Let’s use the example above, but now let’s search only on title if one is pr
6967
</select>
7068
```
7169

72-
73-
7470
### trim, where, set
7571

7672
The previous examples have been conveniently dancing around a notorious dynamic SQL challenge. Consider what would happen if we return to our "if" example, but this time we make "ACTIVE = 1" a dynamic condition as well.
@@ -160,7 +156,7 @@ Here, the *set* element will dynamically prepend the SET keyword, and also elimi
160156

161157
Alternatively, you can achieve the same effect by using *trim* element:
162158

163-
```
159+
```xml
164160
<trim prefix="SET" suffixOverrides=",">
165161
...
166162
</trim>
@@ -195,7 +191,7 @@ This wraps up the discussion regarding the XML configuration file and XML mappin
195191

196192
For using dynamic SQL in annotated mapper class, *script* element can be used. For example:
197193

198-
```xml
194+
```java
199195
@Update({"<script>",
200196
"update Author",
201197
" <set>",

src/site/markdown/getting-started.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Every MyBatis application centers around an instance of SqlSessionFactory. A Sql
2020

2121
Building a SqlSessionFactory instance from an XML file is very simple. It is recommended that you use a classpath resource for this configuration, but you could use any InputStream instance, including one created from a literal file path or a file:// URL. MyBatis includes a utility class, called Resources, that contains a number of methods that make it simpler to load resources from the classpath and other locations.
2222

23-
```
23+
```java
2424
String resource = "org/mybatis/example/mybatis-config.xml";
2525
InputStream inputStream = Resources.getResourceAsStream(resource);
2626
SqlSessionFactory sqlSessionFactory =
@@ -39,10 +39,10 @@ The configuration XML file contains settings for the core of the MyBatis system,
3939
<environment id="development">
4040
<transactionManager type="JDBC"/>
4141
<dataSource type="POOLED">
42-
<property name="driver" value="${driver}"/>
43-
<property name="url" value="${url}"/>
44-
<property name="username" value="${username}"/>
45-
<property name="password" value="${password}"/>
42+
<property name="driver" value="\${driver}"/>
43+
<property name="url" value="\${url}"/>
44+
<property name="username" value="\${username}"/>
45+
<property name="password" value="\${password}"/>
4646
</dataSource>
4747
</environment>
4848
</environments>
@@ -195,7 +195,7 @@ Using this pattern consistently throughout your code will ensure that all databa
195195

196196
Mappers are interfaces that you create to bind to your mapped statements. Instances of the mapper interfaces are acquired from the SqlSession. As such, technically the broadest scope of any mapper instance is the same as the SqlSession from which they were requested. However, the best scope for mapper instances is method scope. That is, they should be requested within the method that they are used, and then be discarded. They do not need to be closed explicitly. While it's not a problem to keep them around throughout a request, similar to the SqlSession, you might find that managing too many resources at this level will quickly get out of hand. Keep it simple, keep Mappers in the method scope. The following example demonstrates this practice.
197197

198-
```
198+
```java
199199
try (SqlSession session = sqlSessionFactory.openSession()) {
200200
BlogMapper mapper = session.getMapper(BlogMapper.class);
201201
// do work

src/site/markdown/java-api.md

Lines changed: 279 additions & 23 deletions
Large diffs are not rendered by default.

src/site/markdown/logging.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ To see MyBatis logging statements you may enable logging on a package, a mapper
5050

5151
Again, how you do this is dependent on the logging implementation in use. We'll show how to do it with SLF4J(Logback). Configuring the logging services is simply a matter of including one or more extra configuration files (e.g. `logback.xml`) and sometimes a new JAR file. The following example configuration will configure full logging services using SLF4J(Logback) as a provider. There are 2 steps.
5252

53-
54-
5553
#### Step 1: Add the SLF4J + Logback JAR files
5654

5755
Because we are using SLF4J(Logback), we will need to ensure its JAR file is available to our application. To use SLF4J(Logback), you need to add the JAR file to your application classpath.
@@ -68,8 +66,6 @@ If you use the maven, you can download jar files by adding following settings on
6866
</dependency>
6967
```
7068

71-
72-
7369
#### Step 2: Configure Logback
7470

7571
Configuring Logback is simple. Suppose you want to enable the log for this mapper:
@@ -167,18 +163,18 @@ Yes, as you may have noticed, there is no difference in configuring logging for
167163

168164
The remaining configuration in the `logback.xml` file is used to configure the appenders, which is beyond the scope of this document. However, you can find more information at the [Logback](https://logback.qos.ch/) website. Or, you could simply experiment with it to see what effects the different configuration options have.
169165

170-
171-
172166
#### Configuration example for Log4j 2
173167

174168
```xml
175-
pom.xml
169+
<!-- pom.xml -->
176170
<dependency>
177171
<groupId>org.apache.logging.log4j</groupId>
178172
<artifactId>log4j-core</artifactId>
179173
<version>2.x.x</version>
180174
</dependency>
181-
log4j2.xml
175+
```
176+
```xml
177+
<!-- log4j2.xml -->
182178
<?xml version="1.0" encoding="UTF-8"?>
183179
<Configuration xmlns="http://logging.apache.org/log4j/2.0/config">
184180

@@ -198,18 +194,18 @@ log4j2.xml
198194
</Configuration>
199195
```
200196

201-
202-
203197
#### Configuration example for Log4j
204198

205-
```properties
206-
pom.xml
199+
```xml
200+
<!-- pom.xml -->
207201
<dependency>
208202
<groupId>log4j</groupId>
209203
<artifactId>log4j</artifactId>
210204
<version>1.2.17</version>
211205
</dependency>
212-
log4j.properties
206+
```
207+
```properties
208+
# log4j.properties
213209
log4j.rootLogger=ERROR, stdout
214210

215211
log4j.logger.org.mybatis.example.BlogMapper=TRACE
@@ -219,12 +215,10 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
219215
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
220216
```
221217

222-
223-
224218
#### Configuration example for JDK logging
225219

226220
```properties
227-
logging.properties
221+
# logging.properties
228222
handlers=java.util.logging.ConsoleHandler
229223
.level=SEVERE
230224

0 commit comments

Comments
 (0)