Object com.ibatis.sqlmap.client.SqlMapExecutor.queryForObject(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.
The parameter object is generally used to supply the input data for the INSERT values.
Parameters:
id The name of the statement to execute.
parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
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.
(这个方法返回的是一个主键object)
Throws:
java.sql.SQLException If an error occurs.
====看下例子=======================
<!-- Insert example, using the Account parameter class -->
<insert id="insertAccount" parameterClass="Account">
insert into ACCOUNT (
ACC_FIRST_NAME,
ACC_LAST_NAME,
ACC_EMAIL)
values (
#firstName#, #lastName#, #emailAddress#
)
</insert>
public static Object insertAccount (Account account) throws SQLException {
return sqlMapper.insert("insertAccount", account);
}
实际上, insertAccount 返回的总是一个null。
原来用法是这样的:
<!-- Insert example, using the Account parameter class -->
<insert id="insertAccount" parameterClass="Account">
insert into ACCOUNT (
ACC_FIRST_NAME,
ACC_LAST_NAME,
ACC_EMAIL)
values (
#firstName#, #lastName#, #emailAddress#
)
<selectKey resultClass="int" keyProperty="id" >
SELECT @@IDENTITY AS ID
</selectKey>
</insert>
关键在嵌套的那句selectKey -
我得表的主键是ID,所以返回的是一个Integer对象,其值就是插入的那个account的id, 不过不知道对于复合主键的情况的结果如何。。。。。。。。
本文来自CSDN博客:http://blog.csdn.net/oswin_jiang/archive/2009/04/30/4138938.aspx
分享到:
相关推荐
ibatis的insert方法的返回值。 介绍了mybaits如何处理返回值的问题。
IBatis.DataMapper.1.6.2 和 IBatis.DataMapper.1.9 开发包
ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战.part07ibatis实战....
ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战.part09ibatis实战....
ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战.part08ibatis实战....
ibatis-2.3.4.726.jar,ibatis-2.3.0.677.jar,ibatis-2.3.3.720.jar下载,都已放入一个压缩包下。
private static SqlMapClient sqlMapClient = null;... sqlMapClient.insert("insertStudent",student); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
ibatis实战.part06 ibatis实战.part06 ibatis实战.part06 ibatis实战.part06
ibatis批处理.doc ibatis批处理.doc
ibatis2.3.4.726.jar ibatis2.3.4.726.jar ibatis2.3.4.726.jar ibatis2.3.4.726.jar
ibatismysql.jar ibatismysql.jar
ibatis.net官方组件 IBatis.DataMapper.1.6.2 IBatis.DataAccess.1.9.2
ibatis教程_准备ibatis环境.raribatis教程_准备ibatis环境.raribatis教程_准备ibatis环境.rar
IBatisNet.Common.1.6.2、IBatis.DataAccess.1.9.2、IBatis.DataMapper.1.6.2
搭建mybatis所需包org.apache.ibatis.annotations.Param @Param
iBATIS 级联.part4iBATIS 级联.part4
Manning.iBATIS.in.Action.Jan.2007.eBook-BBL.pdf Manning.iBATIS.in.Action.Jan.2007.eBook-BBL.pdf Manning.iBATIS.in.Action.Jan.2007.eBook-BBL.pdf
《iBATIS实战》是讲述iBATIS框架的权威著作。书中既详实地介绍了iBATIS的设计理念和基础知识,也讨论了动态SQL、高速缓存、DAD框架等高级主题,还讲解了iBATIS在实际开发中的应用。《iBATIS实战》的最后给出了一个...
提供ibatis2.3.4.8.jar包下载.