@@ -211,60 +211,76 @@ gobatis.RegisterMapperFile(filePath)
211
211
2 . xml示例
212
212
213
213
```
214
- <mapper namespace="test_package.TestTable ">
215
- <sql id="columns_id">`id`,` username`,` password`,`update_time` </sql>
214
+ <mapper namespace="test ">
215
+ <sql id="columns_id">id, username, password,createtime </sql>
216
216
217
217
<select id="selectTestTable">
218
- SELECT <include refid="columns_id"> </include> FROM `TEST_TABLE`
218
+ SELECT <include refid="columns_id"> </include> FROM test_table
219
219
<where>
220
- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
221
- <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
222
- <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
223
- <if test="{TestTable.update_time } != nil">AND `update_time` = #{TestTable.update_time } </if>
220
+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
221
+ <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
222
+ <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
223
+ <if test="{TestTable.createtime } != nil">AND createtime = #{TestTable.createtime } </if>
224
224
</where>
225
225
</select>
226
226
227
227
<select id="selectTestTableCount">
228
- SELECT COUNT(*) FROM `TEST_TABLE`
228
+ SELECT COUNT(*) FROM test_table
229
229
<where>
230
- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
231
- <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
232
- <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
233
- <if test="{TestTable.update_time } != nil">AND `update_time` = #{TestTable.update_time } </if>
230
+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
231
+ <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
232
+ <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
233
+ <if test="{TestTable.createtime } != nil">AND createtime = #{TestTable.createtime } </if>
234
234
</where>
235
235
</select>
236
236
237
237
<insert id="insertTestTable">
238
- INSERT INTO `TEST_TABLE` (`id`,` username`,` password`,`update_time` )
238
+ INSERT INTO test_table (id, username, password,createtime )
239
239
VALUES(
240
240
#{TestTable.id},
241
241
#{TestTable.username},
242
242
#{TestTable.password},
243
- #{TestTable.update_time }
243
+ #{TestTable.createtime }
244
244
)
245
245
</insert>
246
246
247
+ <insert id="insertBatchTestTable">
248
+ INSERT INTO test_table (id,username,password,createtime)
249
+ VALUES
250
+ <foreach item="item" index="index" collection="{0}" open="" separator="," close="">
251
+ (#{item.TestTable.id},#{item.TestTable.username},#{item.TestTable.password},#{item.TestTable.createtime})
252
+ </foreach>
253
+ </insert>
254
+
247
255
<update id="updateTestTable">
248
- UPDATE `TEST_TABLE`
256
+ UPDATE test_table
249
257
<set>
250
- <if test="{TestTable.username} != nil"> ` username` = #{TestTable.username} </if>
251
- <if test="{TestTable.password} != nil"> ` password` = #{TestTable.password} </if>
252
- <if test="{TestTable.update_time } != nil"> `update_time` = #{TestTable.update_time } </if>
258
+ <if test="{TestTable.username} != nil"> username = #{TestTable.username} </if>
259
+ <if test="{TestTable.password} != nil"> password = #{TestTable.password} </if>
260
+ <if test="{TestTable.createtime } != nil"> createtime = #{TestTable.createtime } </if>
253
261
</set>
254
- WHERE `id` = #{TestTable.id}
262
+ WHERE id = #{TestTable.id}
255
263
</update>
256
264
257
265
<delete id="deleteTestTable">
258
- DELETE FROM `TEST_TABLE`
266
+ DELETE FROM test_table
259
267
<where>
260
- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
261
- <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
262
- <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
263
- <if test="{TestTable.update_time } != nil">AND `update_time` = #{TestTable.update_time } </if>
268
+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
269
+ <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
270
+ <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
271
+ <if test="{TestTable.createtime } != nil">AND createtime = #{TestTable.createtime } </if>
264
272
</where>
265
273
</delete>
266
274
</mapper>
267
275
```
276
+ 3 . namespace
277
+
278
+ xml数据或文件注册之后,session参数sqlid与xml action对应关系为:${NAMESPACE}+"."+${ACTION_ID}
279
+
280
+ 以2中的xml为例,调用select的方式为:
281
+ ``` cassandraql
282
+ sess.Select("test.selectTestTable").Param(model).Result(&dataList)
283
+ ```
268
284
269
285
### 8、template
270
286
@@ -285,6 +301,8 @@ gobatis.RegisterTemplateFile(filePath)
285
301
2 . template示例
286
302
287
303
```
304
+ {{define "namespace"}}test{{end}}
305
+
288
306
{{define "selectTestTable"}}
289
307
SELECT id,username,password,createtime FROM test_table
290
308
{{where .Id "AND" "id = " (arg .Id) "" | where .Username "AND" "username = " (arg .Username) | where .Password "AND" "password = " (arg .Password) | where .Createtime "AND" "createtime = " (arg .Createtime)}}
@@ -320,6 +338,16 @@ DELETE FROM test_table
320
338
{{where .Id "AND" "id = " (arg .Id) "" | where .Username "AND" "username = " (arg .Username) | where .Password "AND" "password = " (arg .Password) | where .Createtime "AND" "createtime = " (arg .Createtime)}}
321
339
{{end}}
322
340
```
341
+ 3 . namespace
342
+
343
+ template数据或文件可定义一个名称为namespace的子模版,用以定义namespace。
344
+
345
+ template数据或文件注册之后,session参数sql id与模板对应关系为:${NAMESPACE}+"."+${ACTION_ID}
346
+
347
+ 以2中的template为例,调用select的方式为:
348
+ ``` cassandraql
349
+ sess.Select("test.selectTestTable").Param(model).Result(&dataList)
350
+ ```
323
351
324
352
### 9、gobatis-cmd生成文件使用示例
325
353
0 commit comments