iBatis的SqlMapClient.insert()方法的返回值
来源:互联网 发布:ubuntu 虚拟机 nat 编辑:程序博客网 时间:2024/05/14 23:59
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, 不过不知道对于复合主键的情况的结果如何
- iBatis的SqlMapClient.insert()方法的返回值
- iBatis的SqlMapClient.insert()方法的返回值
- iBatis的SqlMapClient.insert()方法的返回值
- iBatis的SqlMapClient.insert()方法的返回值
- 【ibatis】SqlMapClient.insert返回值与selectKey
- ibatis读取配置文件取得SqlMapClient实例的方法
- ibatis insert返回自增主键的值
- ibatis中insert值的同时返回主键
- ibatis的insert操作返回id
- 通过ibatis的sqlmapclient获得connection连接
- SqlMapClient对象-iBatis操作数据库的接口
- Ibatis中SqlMapClientTemplate和SqlMapClient的区别
- ibatis中SqlMapClientTemplate与SqlMapClient的区别
- Ibatis中SqlMapClientTemplate和SqlMapClient的区别
- [ibatis]关于Ibatis insert后返回值为null的解决办法(转)
- Ibatis insert插入返回值
- ibatis insert返回值问题
- 关于ibatis insert返回值
- 杭电ACM 1008Elevator
- LightOJ 1002 Country Roads(最短路变形(SPFA||贝尔曼))
- POJ1811 (Prime Test Pollard rho整数分解,Miller-Rabin素数测试)
- 【JS设计模式】组合模式
- java注解例子
- iBatis的SqlMapClient.insert()方法的返回值
- AndroidAnnotations使用
- Android中关于键盘的操作
- linux下的io多路复用形象化理解
- HDU 1180 诡异的楼梯(广搜、优先队列)
- 简单扑克游戏
- [leetcode] Implement Queue using Stacks
- 运算符、控制流
- Ruby time方法