@@ -126,7 +126,7 @@ session.Select("select * from test_table where username = #{TestTable.username}"
126126
127127使用
128128```
129- mgr.NewSession().Tx(func(session *gobatis.Session) bool {
129+ mgr.NewSession().Tx(func(session *gobatis.Session) error {
130130 ret := 0
131131 session.Insert("insert_id").Param(testV).Result(&ret)
132132
@@ -138,11 +138,11 @@ session.Select("select * from test_table where username = #{TestTable.username}"
138138 t.Logf("data: %v", v)
139139 }
140140 //commit
141- return true
141+ return nil
142142 })
143143```
144- 1 . 当参数的func返回true ,则提交
145- 2 . 当参数的func返回false ,则回滚
144+ 1 . 当参数的func返回nil ,则提交
145+ 2 . 当参数的func返回非nil的错误 ,则回滚
1461463 . 当参数的func内抛出panic,则回滚
147147
148148### 7、xml
@@ -165,30 +165,30 @@ gobatis.RegisterMapperFile(filePath)
165165
166166```
167167<mapper namespace="test_package.TestTable">
168- <sql id="columns_id">id, username, password, update_time</sql>
168+ <sql id="columns_id">`id`,` username`,` password`,` update_time` </sql>
169169
170170 <select id="selectTestTable">
171- SELECT <include refid="columns_id"> </include> FROM test_table
171+ SELECT <include refid="columns_id"> </include> FROM `TEST_TABLE`
172172 <where>
173- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
174- <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
175- <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
176- <if test="{TestTable.update_time} != nil">AND update_time = #{TestTable.update_time} </if>
173+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
174+ <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
175+ <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
176+ <if test="{TestTable.update_time} != nil">AND ` update_time` = #{TestTable.update_time} </if>
177177 </where>
178178 </select>
179179
180180 <select id="selectTestTableCount">
181- SELECT COUNT(*) FROM test_table
181+ SELECT COUNT(*) FROM `TEST_TABLE`
182182 <where>
183- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
184- <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
185- <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
186- <if test="{TestTable.update_time} != nil">AND update_time = #{TestTable.update_time} </if>
183+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
184+ <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
185+ <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
186+ <if test="{TestTable.update_time} != nil">AND ` update_time` = #{TestTable.update_time} </if>
187187 </where>
188188 </select>
189189
190190 <insert id="insertTestTable">
191- INSERT INTO test_table (id, username, password, update_time)
191+ INSERT INTO `TEST_TABLE` (`id`,` username`,` password`,` update_time` )
192192 VALUES(
193193 #{TestTable.id},
194194 #{TestTable.username},
@@ -198,22 +198,22 @@ gobatis.RegisterMapperFile(filePath)
198198 </insert>
199199
200200 <update id="updateTestTable">
201- UPDATE test_table
201+ UPDATE `TEST_TABLE`
202202 <set>
203- <if test="{TestTable.username} != nil"> username = #{TestTable.username} </if>
204- <if test="{TestTable.password} != nil"> password = #{TestTable.password} </if>
205- <if test="{TestTable.update_time} != nil"> update_time = #{TestTable.update_time} </if>
203+ <if test="{TestTable.username} != nil"> ` username` = #{TestTable.username} </if>
204+ <if test="{TestTable.password} != nil"> ` password` = #{TestTable.password} </if>
205+ <if test="{TestTable.update_time} != nil"> ` update_time` = #{TestTable.update_time} </if>
206206 </set>
207- WHERE id = #{TestTable.id}
207+ WHERE `id` = #{TestTable.id}
208208 </update>
209209
210210 <delete id="deleteTestTable">
211- DELETE FROM test_table
211+ DELETE FROM `TEST_TABLE`
212212 <where>
213- <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND id = #{TestTable.id} </if>
214- <if test="{TestTable.username} != nil">AND username = #{TestTable.username} </if>
215- <if test="{TestTable.password} != nil">AND password = #{TestTable.password} </if>
216- <if test="{TestTable.update_time} != nil">AND update_time = #{TestTable.update_time} </if>
213+ <if test="{TestTable.id} != nil and {TestTable.id} != 0">AND `id` = #{TestTable.id} </if>
214+ <if test="{TestTable.username} != nil">AND ` username` = #{TestTable.username} </if>
215+ <if test="{TestTable.password} != nil">AND ` password` = #{TestTable.password} </if>
216+ <if test="{TestTable.update_time} != nil">AND ` update_time` = #{TestTable.update_time} </if>
217217 </where>
218218 </delete>
219219</mapper>
0 commit comments