@@ -211,60 +211,76 @@ gobatis.RegisterMapperFile(filePath)
2112112 . xml示例
212212
213213```
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>
216216
217217 <select id="selectTestTable">
218- SELECT <include refid="columns_id"> </include> FROM `TEST_TABLE`
218+ SELECT <include refid="columns_id"> </include> FROM test_table
219219 <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>
224224 </where>
225225 </select>
226226
227227 <select id="selectTestTableCount">
228- SELECT COUNT(*) FROM `TEST_TABLE`
228+ SELECT COUNT(*) FROM test_table
229229 <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>
234234 </where>
235235 </select>
236236
237237 <insert id="insertTestTable">
238- INSERT INTO `TEST_TABLE` (`id`,` username`,` password`,`update_time` )
238+ INSERT INTO test_table (id, username, password,createtime )
239239 VALUES(
240240 #{TestTable.id},
241241 #{TestTable.username},
242242 #{TestTable.password},
243- #{TestTable.update_time }
243+ #{TestTable.createtime }
244244 )
245245 </insert>
246246
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+
247255 <update id="updateTestTable">
248- UPDATE `TEST_TABLE`
256+ UPDATE test_table
249257 <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>
253261 </set>
254- WHERE `id` = #{TestTable.id}
262+ WHERE id = #{TestTable.id}
255263 </update>
256264
257265 <delete id="deleteTestTable">
258- DELETE FROM `TEST_TABLE`
266+ DELETE FROM test_table
259267 <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>
264272 </where>
265273 </delete>
266274</mapper>
267275```
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+ ```
268284
269285### 8、template
270286
@@ -285,6 +301,8 @@ gobatis.RegisterTemplateFile(filePath)
2853012 . template示例
286302
287303```
304+ {{define "namespace"}}test{{end}}
305+
288306{{define "selectTestTable"}}
289307SELECT id,username,password,createtime FROM test_table
290308{{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
320338{{where .Id "AND" "id = " (arg .Id) "" | where .Username "AND" "username = " (arg .Username) | where .Password "AND" "password = " (arg .Password) | where .Createtime "AND" "createtime = " (arg .Createtime)}}
321339{{end}}
322340```
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+ ```
323351
324352### 9、gobatis-cmd生成文件使用示例
325353
0 commit comments