我是靠谱客的博主 自信铃铛,这篇文章主要介绍Mybatis update delete 操作的返回值,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

insert,返回值是:新插入行的主键(primary key);需要包含<selectKey>语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
queryForObject,返回的是:一个实例对象或null;需要包含<select>语句,并且指明resultMap;
queryForList,返回的是:实例对象的列表;需要包含<select>语句,并且指明resultMap;

 

关于ibatis的接口,参见其源码(comibatissqlmapclientSqlMapExecutor.java):

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* * Copyright 2004 Clinton Begin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ibatis.sqlmap.client; import com.ibatis.common.util.PaginatedList; import com.ibatis.sqlmap.client.event.RowHandler; import com.ibatis.sqlmap.engine.execution.BatchException; import java.sql.SQLException; import java.util.List; import java.util.Map; /** * This interface declares all methods involved with executing statements * and batches for an SQL Map. * * @see SqlMapSession * @see SqlMapClient */ public interface SqlMapExecutor { /** * Executes a mapped SQL INSERT statement. * Insert is a bit different from other update methods, as it * provides facilities for returning the primary key of the * newly inserted row (rather than the effected rows). This * functionality is of course optional. * <p/> * The parameter object is generally used to supply the input * data for the INSERT values. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @return The primary key of the newly inserted row. This might be automatically * generated by the RDBMS, or selected from a sequence table or other source. * @throws java.sql.SQLException If an error occurs. */ Object insert(String id, Object parameterObject) throws SQLException; /** * Executes a mapped SQL INSERT statement. * Insert is a bit different from other update methods, as it * provides facilities for returning the primary key of the * newly inserted row (rather than the effected rows). This * functionality is of course optional. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @return The primary key of the newly inserted row. This might be automatically * generated by the RDBMS, or selected from a sequence table or other source. * @throws java.sql.SQLException If an error occurs. */ Object insert(String id) throws SQLException; /** * Executes a mapped SQL UPDATE statement. * Update can also be used for any other update statement type, * such as inserts and deletes. Update returns the number of * rows effected. * <p/> * The parameter object is generally used to supply the input * data for the UPDATE values as well as the WHERE clause parameter(s). * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @return The number of rows effected. * @throws java.sql.SQLException If an error occurs. */ int update(String id, Object parameterObject) throws SQLException; /** * Executes a mapped SQL UPDATE statement. * Update can also be used for any other update statement type, * such as inserts and deletes. Update returns the number of * rows effected. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @return The number of rows effected. * @throws java.sql.SQLException If an error occurs. */ int update(String id) throws SQLException; /** * Executes a mapped SQL DELETE statement. * Delete returns the number of rows effected. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the DELETE statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @return The number of rows effected. * @throws java.sql.SQLException If an error occurs. */ int delete(String id, Object parameterObject) throws SQLException; /** * Executes a mapped SQL DELETE statement. * Delete returns the number of rows effected. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @return The number of rows effected. * @throws java.sql.SQLException If an error occurs. */ int delete(String id) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a single object instance. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @return The single result object populated with the result set data, * or null if no result was found * @throws java.sql.SQLException If more than one result was found, or if any other error occurs. */ Object queryForObject(String id, Object parameterObject) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a single object instance. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @return The single result object populated with the result set data, * or null if no result was found * @throws java.sql.SQLException If more than one result was found, or if any other error occurs. */ Object queryForObject(String id) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * the supplied result object. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param resultObject The result object instance that should be populated with result data. * @return The single result object as supplied by the resultObject parameter, populated with the result set data, * or null if no result was found * @throws java.sql.SQLException If more than one result was found, or if any other error occurs. */ Object queryForObject(String id, Object parameterObject, Object resultObject) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @return A List of result objects. * @throws java.sql.SQLException If an error occurs. */ List queryForList(String id, Object parameterObject) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @return A List of result objects. * @throws java.sql.SQLException If an error occurs. */ List queryForList(String id) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects within a certain range. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param skip The number of results to ignore. * @param max The maximum number of results to return. * @return A List of result objects. * @throws java.sql.SQLException If an error occurs. */ List queryForList(String id, Object parameterObject, int skip, int max) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects within a certain range. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @param skip The number of results to ignore. * @param max The maximum number of results to return. * @return A List of result objects. * @throws java.sql.SQLException If an error occurs. */ List queryForList(String id, int skip, int max) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns a number of * result objects that will be handled one at a time by a * RowHandler. * <p/> * This is generally a good approach to take when dealing with large sets * of records (i.e. hundreds, thousands...) that need to be processed without * eating up all of the system resources. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param rowHandler A RowHandler instance * @throws java.sql.SQLException If an error occurs. */ void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns a number of * result objects that will be handled one at a time by a * RowHandler. * <p/> * This is generally a good approach to take when dealing with large sets * of records (i.e. hundreds, thousands...) that need to be processed without * eating up all of the system resources. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @param rowHandler A RowHandler instance * @throws java.sql.SQLException If an error occurs. */ void queryWithRowHandler(String id, RowHandler rowHandler) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects a page at a time. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param pageSize The maximum number of result objects each page can hold. * @return A PaginatedList of result objects. * @throws java.sql.SQLException If an error occurs. * @deprecated All paginated list features have been deprecated */ PaginatedList queryForPaginatedList(String id, Object parameterObject, int pageSize) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects a page at a time. * <p/> * This overload assumes no parameter is needed. * * @param id The name of the statement to execute. * @param pageSize The maximum number of result objects each page can hold. * @return A PaginatedList of result objects. * @throws java.sql.SQLException If an error occurs. * @deprecated All paginated list features have been deprecated */ PaginatedList queryForPaginatedList(String id, int pageSize) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects that will be keyed into a Map. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param keyProp The property to be used as the key in the Map. * @return A Map keyed by keyProp with values being the result object instance. * @throws java.sql.SQLException If an error occurs. */ Map queryForMap(String id, Object parameterObject, String keyProp) throws SQLException; /** * Executes a mapped SQL SELECT statement that returns data to populate * a number of result objects from which one property will be keyed into a Map. * <p/> * The parameter object is generally used to supply the input * data for the WHERE clause parameter(s) of the SELECT statement. * * @param id The name of the statement to execute. * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.). * @param keyProp The property to be used as the key in the Map. * @param valueProp The property to be used as the value in the Map. * @return A Map keyed by keyProp with values of valueProp. * @throws java.sql.SQLException If an error occurs. */ Map queryForMap(String id, Object parameterObject, String keyProp, String valueProp) throws SQLException; /** * Starts a batch in which update statements will be cached before being sent to * the database all at once. This can improve overall performance of updates update * when dealing with numerous updates (e.g. inserting 1:M related data). * * @throws java.sql.SQLException If the batch could not be started. */ void startBatch() throws SQLException; /** * Executes (flushes) all statements currently batched. * * @return the number of rows updated in the batch * @throws java.sql.SQLException If the batch could not be executed or if any of the statements * fails. */ int executeBatch() throws SQLException; /** * Executes (flushes) all statements currently batched. * * @return a List of BatchResult objects. There will be one element in the * list for each sub-batch executed. A sub-batch is created by adding a statement * to the batch that does not equal the prior statement. * @throws SQLException if a database access error occurs, or the drive * does not support batch statements * @throws BatchException if the driver throws BatchUpdateException * @see com.ibatis.sqlmap.engine.execution.BatchException */ List executeBatchDetailed() throws SQLException, BatchException; }

 

转载于:https://my.oschina.net/zjllovecode/blog/1581677

最后

以上就是自信铃铛最近收集整理的关于Mybatis update delete 操作的返回值的全部内容,更多相关Mybatis内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部