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">selectnextval('desktop_unlock_tag_id_seq') as id</selectKey>insert intodesktop_unlock_tag(id,name,description,priority)values(#id:INTEGER#,#name:VARCHAR#,#description:VARCHAR#,#priority:INTEGER#)</insert><update id="updateUnlockTagInfo" parameterClass="map">updatedesktop_unlock_tagset modify_time=now(),priority=#priority:INTEGER#,name=#name:VARCHAR#,description=#description:VARCHAR#whereid=#id:INTEGER#</update><delete id="deleteUnlockTagInfo" parameterClass="int">delete fromdesktop_unlock_tagwhere id=#value:INTEGER#</delete><select id="countUnlockTagInfo" resultClass="int">select count(*)fromdesktop_unlock_tag</select><sql id="selectUnlockTagInfo">selectid,name,description,priorityfromdesktop_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 bymodify_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 implementsUnlockTagDao {@Overridepublic 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;}@Overridepublic 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;}}@Overridepublic 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;}}@Overridepublic UnlockTagInfo findItemById(Integer id) {SqlMapClientTemplate template = this.getSqlMapClientTemplate();UnlockTagInfo item = (UnlockTagInfo) template.queryForObject("DesktopCommon.findUnlockTagInfoById", id);return item;}@Overridepublic 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& ...
- mybatis进行CRUD操作时返回值不为影响的条数,为null
对应自己的情况多试试看,总有一种方法可以解决吧! 1.如果报期望的返回值为null而原始返回值类型为int的错误 则将Dao/mapper接口中的函数的返回值类型改为Integer,在方法调用时使用. ...
- 关于ibatis使用HashMap接收返回值的映射报错问题
关于ibatis使用HashMap接收返回值的映射报错问题 问题描述 原因分析 问题处理 问题描述 我们在使用ibatis时,有时候会把sql的返回值类型设置为HashMap,在极少数情况下会出现映射 ...
- Jav详细介绍的Mapper对应的Mybatis xml查询结果resultType返回值类型
一.返回一般数据类型 此实列总代用的是string类型 列:比如我们要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值 ...
- springboot集成mybatis实现数据库操作
文章目录 前言 一.创建一个sprinboot项目 二.修改pom文件,添加mybatis相关依赖 1.添加mysql驱动 2.修改build标签 三.写mapper接口和控制层 1.初始化数据库 链 ...
- c#数据库訪问返回值类型为SqlDataReader时使用using时注意的问题
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010512579/article/details/24011761 在封装通用 SQLSERVER ...
- 一个比较怪异的操作,没有返回值
对于这个程序,我是无话可说,不知道哪个老师出的题,让我倍感迷茫 #include<stdio.h> int fun(int a, int b, int c) { a = 456; b = ...
- 实习笔记 —— MyBatis II (MyBatis基本数据库操作)
系列文章目录 实习笔记 -- Spring基础 实习笔记 -- IOC反转控制(xml配置文件 + 注解) 实习笔记 -- AOP开发I 实习笔记-- AOP开发II(AOP中Advice的类型) 实 ...
- mysql resulttype_常见的MyBatis中查询结果resultType返回值类型
一.返回一般数据类型 比如要根据 id 属性获得数据库中的某个字段值. mapper (dao)接口: // 根据 id 获得数据库中的 username 字段的值 String getStuName ...
最新文章
- 什么是php工作流,什么是工作流?
- Python运维-获取当前操作系统的各种信息
- Java—TCP与HTTP连接
- pthread_create会导致内存泄露
- Zookeeper Watch监听
- 《HTML 5与CSS 3 权威指南(第3版·上册)》——1.2 HTML 5深受欢迎的理由
- linux日常检查,Linux日常检查的shell
- 提高C#编程水平的50个要诀
- 数字调制中比特率和波特率的关系
- windows 资源监视器
- Excel绘制CDF图
- C# eval()函数浅谈
- 是你需要的前端编码风格吗?
- LeetCode-179-最大数
- 微信公众平台找自己APPID
- w500 安装 gentoo相关优化
- 跟涛哥一起学嵌入式 27:一个小故事,让你明白进程、线程和协程的区别
- java模拟内存溢出并分析_本地模拟内存溢出并分析Dump文件
- 密码是一个好东西,担当你把密码忘记了的时候,密码又是一个很老火的事情了,就如 把数据库的密码忘记了的事后一样。...
- 三星s10更新Android10,经历了三星s10的最近一次升级,我对安卓对三星有了新的认知...
热门文章
- bartlett方差齐性检验_方差齐性检验
- python吧_python初始与安装 - Python东
- PHP随机静态页面生成系统源码雨尘SEO系统v1.3
- java 获取 jframe 内容_Java如何获取组件的JFrame?
- pydev工程linux运行,Linux平台下Python的安装及IDE开发环境搭建
- java 证书公钥 私钥_ssl - 在Java Key中导入私钥/公钥证书对
- PhotoZoom专业版-图像无损放大工具
- 系统架构设计上需要注意的
- jQuery: 判断指针是否在某元素内 How do I check if the mouse is over an element
- Intro.js轻松搞定页面引导流程