新增返回主键

MySql和SqlServer 支持主键自增长的数据库:

<insert id="add" parameterType="com.yweb.entity.User" keyProperty="id" useGeneratedKeys="true">  
    insert into (name,age) values ('zs',18)  
</insert>

 

Oracle不支持主键自增长的数据库:

<insert id="insert" parameterType="AltName">   
    <selectKey resultType="long" keyProperty="id">   
        SELECT SEQ_TEST.NEXTVAL FROM DUAL    
    </selectKey>   
    insert into altname(primaryName,alternateName,type)values(#{primaryName},#{alternateName},#{type})    
</insert>

 

posted @ 2018-05-27 14:38  yifanSJ  阅读(204)  评论(0编辑  收藏  举报