@@ -126,7 +126,7 @@ session.Select("select * from test_table where username = #{TestTable.username}"
126
126
127
127
使用
128
128
```
129
- mgr.NewSession().Tx(func(session *gobatis.Session) bool {
129
+ mgr.NewSession().Tx(func(session *gobatis.Session) error {
130
130
ret := 0
131
131
session.Insert("insert_id").Param(testV).Result(&ret)
132
132
@@ -138,11 +138,11 @@ session.Select("select * from test_table where username = #{TestTable.username}"
138
138
t.Logf("data: %v", v)
139
139
}
140
140
//commit
141
- return true
141
+ return nil
142
142
})
143
143
```
144
- 1 . 当参数的func返回true ,则提交
145
- 2 . 当参数的func返回false ,则回滚
144
+ 1 . 当参数的func返回nil ,则提交
145
+ 2 . 当参数的func返回非nil的错误 ,则回滚
146
146
3 . 当参数的func内抛出panic,则回滚
147
147
148
148
### 7、xml
@@ -165,30 +165,30 @@ gobatis.RegisterMapperFile(filePath)
165
165
166
166
```
167
167
<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>
169
169
170
170
<select id="selectTestTable">
171
- SELECT <include refid="columns_id"> </include> FROM test_table
171
+ SELECT <include refid="columns_id"> </include> FROM `TEST_TABLE`
172
172
<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>
177
177
</where>
178
178
</select>
179
179
180
180
<select id="selectTestTableCount">
181
- SELECT COUNT(*) FROM test_table
181
+ SELECT COUNT(*) FROM `TEST_TABLE`
182
182
<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>
187
187
</where>
188
188
</select>
189
189
190
190
<insert id="insertTestTable">
191
- INSERT INTO test_table (id, username, password, update_time)
191
+ INSERT INTO `TEST_TABLE` (`id`,` username`,` password`,` update_time` )
192
192
VALUES(
193
193
#{TestTable.id},
194
194
#{TestTable.username},
@@ -198,22 +198,22 @@ gobatis.RegisterMapperFile(filePath)
198
198
</insert>
199
199
200
200
<update id="updateTestTable">
201
- UPDATE test_table
201
+ UPDATE `TEST_TABLE`
202
202
<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>
206
206
</set>
207
- WHERE id = #{TestTable.id}
207
+ WHERE `id` = #{TestTable.id}
208
208
</update>
209
209
210
210
<delete id="deleteTestTable">
211
- DELETE FROM test_table
211
+ DELETE FROM `TEST_TABLE`
212
212
<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>
217
217
</where>
218
218
</delete>
219
219
</mapper>
0 commit comments