ibatis插入数据后返回id
ORACLE数据库
首先看配置
?<insert id="insertOperation">
? insert into operation? (id,name,desc)?? values?? (operation_seq.nextval,#name#,#desc#)
??? <selectKey resultkeyProperty="Id" >
????? select operation_seq.currval as id from dual
??? </selectKey>
?</insert>
首先来解释下Id,这个是对应的BEAN里面的属性,千万别配错了,否则拿不到数据
id是operation_seq.currval的一个外键,可以随便设置,不过最好是和数据库里面的id名称对应,这样避免出错
long是Id的类型,这个不要弄错了,当然你可以返回很多类型,比如int等其他数字类型,但是要和Id的类型对应
最后我们来实现访问方法
public Operation insertOperation(Operation ope){
? getSqlMapClientTemplate().insert("insertOperation",ope);
? return ope;
}
?