Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章;还是看源代码(详见最后附录)中的注释,最有效了!
insert,返回值是:新插入行的主键(primary key);需要包含<selectKey>语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
queryForObject,返回的是:一个实例对象或null;需要包含<select>语句,并且指明resultMap;
queryForList,返回的是:实例对象的列表;需要包含<select>语句,并且指明resultMap;
我的配置文件如下(desktop_common_sqlMap.xml):
- <typeAlias alias="UnlockTagInfo" type="com.desktop.common.bean.UnlockTagInfo" />
- <resultMap class="UnlockTagInfo" id="UnlockTagInfoResult">
- <result column="id" property="id" jdbcType="INTEGER" />
- <result column="name" property="name" jdbcType="VARCHAR" />
- <result column="description" property="description" jdbcType="VARCHAR" />
- <result column="priority" property="priority" jdbcType="INTEGER" />
- </resultMap>
- <insert id="insertUnlockTagInfo" parameterClass="map">
- <selectKey resultClass="int" keyProperty="id">
- select
- nextval('desktop_unlock_tag_id_seq') as id
- </selectKey>
- insert into
- desktop_unlock_tag(id,name,description,priority)
- values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)
- </insert>
- <update id="updateUnlockTagInfo" parameterClass="map">
- update
- desktop_unlock_tag
- set modify_time=now(),priority=#priority:INTEGER#,
- name=#name:VARCHAR#,description=#description:VARCHAR#
- where
- id=#id:INTEGER#
- </update>
- <delete id="deleteUnlockTagInfo" parameterClass="int">
- delete from
- desktop_unlock_tag
- where id=#value:INTEGER#
- </delete>
- <select id="countUnlockTagInfo" resultClass="int">
- select count(*)
- from
- desktop_unlock_tag
- </select>
- <sql id="selectUnlockTagInfo">
- select
- id,name,description,priority
- from
- desktop_unlock_tag
- </sql>
- <select id="findUnlockTagInfoById" parameterClass="int"
- resultMap="UnlockTagInfoResult">
- <include refid="selectUnlockTagInfo" />
- where id=#id:INTEGER#
- </select>
- <select id="listUnlockTagInfo" parameterClass="map"
- resultMap="UnlockTagInfoResult">
- <include refid="selectUnlockTagInfo" />
- order by
- modify_time desc limit #size:INTEGER#
- offset #start:INTEGER#
- </select>
<typeAlias alias="UnlockTagInfo" type="com.desktop.common.bean.UnlockTagInfo" />
<resultMap class="UnlockTagInfo" id="UnlockTagInfoResult">
<result column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="priority" property="priority" jdbcType="INTEGER" />
</resultMap>
<insert id="insertUnlockTagInfo" parameterClass="map">
<selectKey resultClass="int" keyProperty="id">
select
nextval('desktop_unlock_tag_id_seq') as id
</selectKey>
insert into
desktop_unlock_tag(id,name,description,priority)
values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)
</insert>
<update id="updateUnlockTagInfo" parameterClass="map">
update
desktop_unlock_tag
set modify_time=now(),priority=#priority:INTEGER#,
name=#name:VARCHAR#,description=#description:VARCHAR#
where
id=#id:INTEGER#
</update>
<delete id="deleteUnlockTagInfo" parameterClass="int">
delete from
desktop_unlock_tag
where id=#value:INTEGER#
</delete>
<select id="countUnlockTagInfo" resultClass="int">
select count(*)
from
desktop_unlock_tag
</select>
<sql id="selectUnlockTagInfo">
select
id,name,description,priority
from
desktop_unlock_tag
</sql>
<select id="findUnlockTagInfoById" parameterClass="int"
resultMap="UnlockTagInfoResult">
<include refid="selectUnlockTagInfo" />
where id=#id:INTEGER#
</select>
<select id="listUnlockTagInfo" parameterClass="map"
resultMap="UnlockTagInfoResult">
<include refid="selectUnlockTagInfo" />
order by
modify_time desc limit #size:INTEGER#
offset #start:INTEGER#
</select>
我的DAO源码如下:
- public class UnlockTagDaoImpl extends SqlMapClientDaoSupport implements
- UnlockTagDao {
- @Override
- public Integer addItem(String name, String desc, Integer priority) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- Map<String, Object> args = new HashMap<String, Object>();
- args.put("name", name);
- args.put("description", desc);
- args.put("priority", priority);
- Object key = template.insert("DesktopCommon.insertUnlockTagInfo", args);
- return (Integer) key;
- }
- @Override
- public boolean updateItem(Integer id, String name, String description,
- Integer priority) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- Map<String, Object> args = new HashMap<String, Object>();
- args.put("id", id);
- args.put("name", name);
- args.put("description", description);
- args.put("priority", priority);
- try {
- int c = template.update("DesktopCommon.updateUnlockTagInfo", args);
- if (c > 0) {
- return true;
- }
- return false;
- } catch (Exception e) {
- return false;
- }
- }
- @Override
- public boolean deleteItem(Integer id) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- try {
- int c = template.delete("DesktopCommon.deleteUnlockTagInfo", id);
- if (c > 0) {
- return true;
- }
- return false;
- } catch (Exception e) {
- return false;
- }
- }
- @Override
- public UnlockTagInfo findItemById(Integer id) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- UnlockTagInfo item = (UnlockTagInfo) template.queryForObject(
- "DesktopCommon.findUnlockTagInfoById", id);
- return item;
- }
- @Override
- public PagedList<UnlockTagInfo> listAll(Integer nStart, Integer nSize,
- boolean bCountTotal) {
- SqlMapClientTemplate template = this.getSqlMapClientTemplate();
- PagedList<UnlockTagInfo> result = new PagedList<UnlockTagInfo>();
- if (bCountTotal) {
- int total = (Integer) template
- .queryForObject("DesktopCommon.countUnlockTagInfo");
- result.setTotal(total);
- }
- Map<String, Integer> args = new HashMap<String, Integer>();
- args.put("start", nStart);
- args.put("size", nSize);
- @SuppressWarnings("unchecked")
- List<UnlockTagInfo> items = template.queryForList(
- "DesktopCommon.listUnlockTagInfo", args);
- result.setData(items);
- return result;
- }
- }
public class UnlockTagDaoImpl extends SqlMapClientDaoSupport implements
UnlockTagDao {
@Override
public Integer addItem(String name, String desc, Integer priority) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
Map<String, Object> args = new HashMap<String, Object>();
args.put("name", name);
args.put("description", desc);
args.put("priority", priority);
Object key = template.insert("DesktopCommon.insertUnlockTagInfo", args);
return (Integer) key;
}@Override
public boolean updateItem(Integer id, String name, String description,
Integer priority) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
Map<String, Object> args = new HashMap<String, Object>();
args.put("id", id);
args.put("name", name);
args.put("description", description);
args.put("priority", priority);
try {
int c = template.update("DesktopCommon.updateUnlockTagInfo", args);
if (c > 0) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
} @Override
public boolean deleteItem(Integer id) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
try {
int c = template.delete("DesktopCommon.deleteUnlockTagInfo", id);
if (c > 0) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
} @Override
public UnlockTagInfo findItemById(Integer id) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
UnlockTagInfo item = (UnlockTagInfo) template.queryForObject(
"DesktopCommon.findUnlockTagInfoById", id);
return item;
} @Override
public PagedList<UnlockTagInfo> listAll(Integer nStart, Integer nSize,
boolean bCountTotal) {
SqlMapClientTemplate template = this.getSqlMapClientTemplate();
PagedList<UnlockTagInfo> result = new PagedList<UnlockTagInfo>();
if (bCountTotal) {
int total = (Integer) template
.queryForObject("DesktopCommon.countUnlockTagInfo");
result.setTotal(total);
}
Map<String, Integer> args = new HashMap<String, Integer>();
args.put("start", nStart);
args.put("size", nSize);
@SuppressWarnings("unchecked")
List<UnlockTagInfo> items = template.queryForList(
"DesktopCommon.listUnlockTagInfo", args);
result.setData(items);
return result;
}
}
关于ibatis的接口,参见其源码(com\ibatis\sqlmap\client\SqlMapExecutor.java):
- /*
- * 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;
- }
/*
* 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;
}
Mybatis/Ibatis,数据库操作的返回值的更多相关文章
- 【转】Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...
- 【转】 Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...
- Mybatis数据库操作的返回值
mybatis配置 <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis ...
- MyBatis的数据库操作
MyBatis的数据库操作 大学毕业有一段时间了,作为一名没有任何开发工作经验的大专毕业生想找到一份软件开发的工作确实很难,但我运气还算不错,应聘上一份java web开发的工作.作为一名新人,老板给 ...
- 【mybatis】mybatis中insert操作,返回自增id
需求是这样的: mybatis中insert操作,返回自增id,因为这个自增id需要给后续业务用到. 原本是这样的: 将insert语句传入,正常执行insert操作,返回int永远是 0[失败] 或 ...
- 关于C#操作数据库ExecuteNonQuery()的返回值问题
) { retValue = AccessCon.ExecuteSql(sql = "update salesData set sellingPrize='" + man.Sell ...
- Mybatis(二)简化Mybatis实现数据库操作
要操作的数据库: 一.与数据库对应的bean类 public class User { private String username; private String sex; private Str ...
- Mybatis在insert操作时返回主键
今天在写项目的时候,遇到一个需求,就是在像数据库插入数据的时候,要保留插入数据的主键,以便后续进行级联时,可以将该主键作为另张表的外键. 但是在正常情况下我们使用插入语句返回的是int型,含义是影响该 ...
- MyBatis insert/delete/update 的返回值
insert,返回值是:新插入行的主键(primary key):需要包含<selectKey>语句,才会返回主键,否则返回值为null. <insert id="inse ...
随机推荐
- CentOS7配置中文支持与部署GitLab服务器
给你的 CentOS 7 安装中文支持 1.首先需要中文字体以便支持命令行终端的中文显示需求: yum groupinstall "fonts" 碰到提示输入 y 回车继续安装,大 ...
- 【洛谷P2722 USACO】 总分 01背包模板
P2722 总分 Score Inflation 题目背景 学生在我们USACO的竞赛中的得分越多我们越高兴. 我们试着设计我们的竞赛以便人们能尽可能的多得分,这需要你的帮助 题目描述 我们可以从几个 ...
- toString方法和valueof()方法的区别
JavaScript引用类型之Array数组的toString()和valueof()方法的区别 一.转换方法 1.在JavaScript中几乎所有对象都具有toLocaleString().to ...
- Linux安装MariaDB(Mysql)和简单配置 mariadb
Linux安装MariaDB(Mysql)和简单配置 1.安装MariaDB 安装命令 yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动Ma ...
- Primitive Topology
原文:Primitive Topology 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737/article/details/78 ...
- DirectX11笔记(二)--Direct3D初始化1之基本概念
原文:DirectX11笔记(二)--Direct3D初始化1之基本概念 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737/art ...
- 一文纵览EMAS 到底内含多少阿里核心技术能力
申请阿里云EMAS,体验一站式移动研发平台,更多精彩尽在开发者会场 EMAS的整体定位是阿里巴巴移动技术对外输出的主窗口,沉淀了阿里巴巴近10年在移动互联网技术架构上的积累以及在一系列垂直场景中所实践 ...
- 【转载】ubuntu下编写字符设备驱动程序-入门篇
在ubuntu初学驱动,觉得挺有用的. http://www.eefocus.com/jefby1990/blog/13-02/291628_c39b8.html
- asp.net ajax客户端框架如何调用Web Service
asp.net ajax客户端框架如何调用Web Service 1:Web Service类添加 [System.Web.Script.Services.ScriptService]特性2:需要异步 ...
- Add Binary字符数字相加,字符串合成
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...