Skip to content

Commit 1b0e149

Browse files
committed
Change to use attribute tag on XML mapper
1 parent 46967a1 commit 1b0e149

File tree

2 files changed

+21
-73
lines changed

2 files changed

+21
-73
lines changed

src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/SqlSessionTest.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,6 @@ void testUpdate() {
169169
}
170170
}
171171

172-
@Test
173-
void testUpdateWithEmptyComment() {
174-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
175-
Name name = new Name();
176-
name.setFirstName("Thymeleaf");
177-
name.setLastName("MyBatis");
178-
sqlSession.insert("org.mybatis.scripting.thymeleaf.integrationtest.mapper.XmlNameSqlSessionMapper.insert", name);
179-
180-
Name updatingName = new Name();
181-
updatingName.setId(name.getId());
182-
updatingName.setFirstName("Thymeleaf3");
183-
updatingName.setLastName("MyBatis3");
184-
sqlSession.update("org.mybatis.scripting.thymeleaf.integrationtest.mapper.XmlNameSqlSessionMapper.updateWithEmptyComment", updatingName);
185-
186-
Name loadedName = sqlSession.selectOne("org.mybatis.scripting.thymeleaf.integrationtest.mapper.XmlNameSqlSessionMapper.findById_value", name.getId());
187-
Assertions.assertEquals(updatingName.getFirstName(), loadedName.getFirstName());
188-
Assertions.assertEquals(updatingName.getLastName(), loadedName.getLastName());
189-
}
190-
}
191-
192172
@Test
193173
void testDelete() {
194174
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
@@ -204,23 +184,6 @@ void testDelete() {
204184
}
205185
}
206186

207-
@Test
208-
void testFindByNameWithEmptyComment() {
209-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
210-
Name name = new Name();
211-
name.setFirstName("Thymeleaf");
212-
name.setLastName("MyBatis");
213-
sqlSession.insert("org.mybatis.scripting.thymeleaf.integrationtest.mapper.XmlNameSqlSessionMapper.insert", name);
214-
215-
NameParam param = new NameParam();
216-
param.setFirstName(name.getFirstName());
217-
param.setLastName(name.getLastName());
218-
Name loadedName = sqlSession.selectOne("org.mybatis.scripting.thymeleaf.integrationtest.mapper.XmlNameSqlSessionMapper.findByNameWithEmptyComment", param);
219-
Assertions.assertEquals(param.getFirstName(), loadedName.getFirstName());
220-
Assertions.assertEquals(param.getLastName(), loadedName.getLastName());
221-
}
222-
}
223-
224187

225188
@Test
226189
void testCustomBindVariables() {

src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/XmlNameSqlSessionMapper.xml

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,26 @@
2323

2424
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
2525
INSERT INTO names (firstName, lastName)
26-
VALUES (/*[('#{firstName}')]*/ 'Taro', /*[('#{lastName}')]*/ 'Yamada')
26+
VALUES ( /*[# mb:p='firstName']*/ 'Taro' /*[/]*/, /*[# mb:p='lastName']*/ 'Yamada' /*[/]*/)
2727
</insert>
2828

2929
<update id="update">
3030
<![CDATA[
3131
UPDATE names
3232
SET id = id
33-
/*[# th:if="${firstName} != null"]*/
34-
,firstName = /*[('#{firstName}')]*/ 'Taro'
33+
/*[# th:if='${firstName} != null']*/
34+
,firstName = /*[# mb:p='firstName']*/ 'Taro' /*[/]*/
3535
/*[/]*/
36-
/*[# th:if="${lastName} != null"]*/
37-
,lastName = /*[('#{lastName}')]*/ 'Yamada'
38-
/*[/]*/
39-
WHERE id = /*[('#{id}')]*/ 1
36+
/*[# th:if='${lastName} != null']*/
37+
,firstName = /*[# mb:p='lastName']*/ 'Yamada' /*[/]*/
38+
/*[/]*/
39+
WHERE id = /*[# mb:p='id']*/ 1 /*[/]*/
4040
]]>
4141
</update>
4242

43-
<update id="updateWithEmptyComment">
44-
UPDATE names
45-
SET firstName = /*[('#{firstName}')]*/ 'Taro' ,lastName = /*[('#{lastName}')]*/ 'Yamada' /**/ WHERE id = /*[('#{id}')]*/ 1
46-
</update>
47-
4843
<delete id="delete">
4944
DELETE FROM names
50-
WHERE id = /*[('#{id}')]*/ 1
45+
WHERE id = /*[# mb:p='id']*/ 1 /*[/]*/
5146
</delete>
5247

5348
<select id="getAllNames" resultType="Name">
@@ -64,20 +59,15 @@
6459
<select id="findById_value" resultType="Name">
6560
SELECT * FROM names
6661
WHERE 1 = 1
67-
/*[# th:if="${value} != null"]*/
68-
AND id = /*[('#{value}')]*/ 1
62+
/*[# th:if='${value} != null']*/
63+
AND id = /*[# mb:p='value']*/ 1 /*[/]*/
6964
/*[/]*/
7065
</select>
7166

72-
<select id="findByNameWithEmptyComment" resultType="Name">
73-
SELECT * FROM names
74-
WHERE firstName = /*[('#{firstName}')]*/ 'Taro' /**/ AND lastName = /*[('#{lastName}')]*/
75-
</select>
76-
7767
<select id="findUsing_parameter" resultType="Name">
7868
SELECT * FROM names WHERE 1 = 1
79-
/*[# th:if="${_parameter.id} != null"]*/
80-
AND id = /*[('#{_parameter.id}')]*/ 1
69+
/*[# th:if='${_parameter.id} != null']*/
70+
AND id = /*[# mb:p='_parameter.id']*/ 1 /*[/]*/
8171
/*[/]*/
8272
</select>
8373

@@ -86,35 +76,30 @@
8676
</select>
8777

8878
<sql id="inValues">
89-
/*[# th:if="${not #lists.isEmpty(list)}"]*/
90-
AND id IN (
91-
/*[# th:each="value : ${list}"]*/
92-
/*[('#{list[' + ${valueStat.index} + ']}')]*/ 1
93-
/*[(${valueStat.last ? '' : ','})]*/
94-
/*[/]*/
95-
)
79+
/*[# th:if='${not #lists.isEmpty(list)}']*/
80+
AND id IN ( /*[# mb:p='list']*/ 1 /*[/]*/ )
9681
/*[/]*/
9782
</sql>
9883

9984
<select id="findDatabaseId" resultType="string" databaseId="hsql">
100-
SELECT /*[('#{_databaseId}')]*/ 'test db'
85+
SELECT /*[# mb:p='_databaseId']*/ 'test db' /*[/]*/
10186
FROM INFORMATION_SCHEMA.SYSTEM_USERS
10287
</select>
10388

10489
<select id="findDatabaseId" resultType="string" databaseId="h2">
105-
SELECT /*[('#{_databaseId}')]*/ 'test db'
90+
SELECT /*[# mb:p='_databaseId']*/ 'test db' /*[/]*/
10691
</select>
10792

10893
<select id="findByName" resultType="Name">
109-
/*[# mb:bind="patternFirstName=|${firstName}%|, patternLastName=|${lastName}%|" /]*/
94+
/*[# mb:bind='patternFirstName=|${firstName}%|, patternLastName=|${lastName}%|' /]*/
11095

11196
SELECT * FROM names
11297
WHERE 1 = 1
113-
/*[# th:if="${firstName} != null"]*/
114-
AND firstName LIKE /*[('#{patternFirstName}')]*/ 'Taro'
98+
/*[# th:if='${firstName} != null']*/
99+
AND firstName LIKE /*[# mb:p='patternFirstName']*/ 'Taro' /*[/]*/
115100
/*[/]*/
116-
/*[# th:if="${lastName} != null"]*/
117-
AND lastName LIKE /*[('#{patternLastName}')]*/ 'Yamada'
101+
/*[# th:if='${lastName} != null']*/
102+
AND lastName LIKE /*[# mb:p='patternLastName']*/ 'Yamada' /*[/]*/
118103
/*[/]*/
119104
</select>
120105

0 commit comments

Comments
 (0)