首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ibatis selectKey 配备

2012-10-25 
ibatis selectKey 配置!--??My?sql?SEQUENCE--????insert???idinsertUser-MY-SQL???parameterClass

ibatis selectKey 配置

<!--??My?sql?SEQUENCE-->???
?ibatis selectKey 配备<insert???id="insertUser-MY-SQL"???parameterClass="user">???
?ibatis selectKey 配备??????INSERT???INTO???T_USER???(name,?sex)?VALUES?(#name#,#sex#)???
?ibatis selectKey 配备??????<selectKey???resultClass="int"???keyProperty="id"?>???
?ibatis selectKey 配备??????????SELECT???LAST_INSERT_ID()?as?id??
?ibatis selectKey 配备??????</selectKey>???
?ibatis selectKey 配备</insert>?
?ibatis selectKey 配备
?ibatis selectKey 配备<!--?Oracle?SEQUENCE??-->???
?ibatis selectKey 配备<insert?id="insertUser-ORACLE"?parameterClass="user">????
?ibatis selectKey 配备<selectKey?resultClass="int"?keyProperty="id"?type="pre">????
?ibatis selectKey 配备<![CDATA[
?ibatis selectKey 配备SELECT?STOCKIDSEQUENCE.NEXTVAL?AS?ID?FROM?DUAL
?ibatis selectKey 配备]]>??
?ibatis selectKey 配备</selectKey>?
?ibatis selectKey 配备<![CDATA[
?ibatis selectKey 配备INSERT?INTO?t_user(id,name,sex)VALUES(#id#,#name#,#sex#)
?ibatis selectKey 配备]]>
?ibatis selectKey 配备</insert>?
?ibatis selectKey 配备
?ibatis selectKey 配备<!--?Microsoft?SQL?Server?IDENTITY?Column?-->????
?ibatis selectKey 配备<insert??id="insertUser-MS-SQL"?parameterClass="user?">????
?ibatis selectKey 配备<![CDATA[
?ibatis selectKey 配备INSERT???INTO???T_USER???(name,?sex)?VALUES???(#name#,#sex#)??
?ibatis selectKey 配备]]>????
?ibatis selectKey 配备<selectKey?resultClass="int"?keyProperty="id"?type="post">????
?ibatis selectKey 配备<![CDATA[
?ibatis selectKey 配备SELECT?@@IDENTITY?AS?ID?
?ibatis selectKey 配备]]>?
?ibatis selectKey 配备<!--?该方法不安全?应当用SCOPE_IDENTITY()?但这个函数属于域函数,需要在一个语句块中执行。?-->??
?ibatis selectKey 配备</selectKey>????
?ibatis selectKey 配备</insert>?
?ibatis selectKey 配备
?ibatis selectKey 配备<!--?Microsoft?SQL?Server?IDENTITY?Column?改进-->????
?ibatis selectKey 配备<insert?id="insertUser-MS-SQL"?parameterClass="user">????
?ibatis selectKey 配备<selectKey?resultClass="int"?keyProperty="id">????
?ibatis selectKey 配备<![CDATA[
?ibatis selectKey 配备INSERT???INTO???T_USER???(name,?sex)?VALUES???(#name#,#sex#)???
?ibatis selectKey 配备???SELECT?SCOPE_IDENTITY()?AS?ID?
?ibatis selectKey 配备]]>??
?ibatis selectKey 配备</selectKey>????
?ibatis selectKey 配备</insert>?
----------------------------------------------------

以sql server为例,举个实例:

配置文件中:

<insert id="saveProject" parameter>
??<selectKey resultkeyProperty="projectId">??
??<![CDATA[
??insert into PROJECT(projectName,description)
??values(#projectName#,#description#)?
??SELECT SCOPE_IDENTITY() AS projectId
??]]>
?</selectKey>
?</insert>?

?

DaoImpl中代码:

?public Integer saveProject(ProjectVO projectVO){
??return (Integer)getSqlMapClientTemplate().insert("commonMap.saveProject", projectVO);
?}

热点排行