mybatis自增长插入id

第一种:

<insert id="insertUser" parameterClass="ibatis.User"> 
      <selectKey resultType="int" keyProperty="id" order="BEFORE"> 
        select SEQ_TEST.NEXTVAL from dual 
      </selectKey>          
           insert into user 
          (name,password) 
          values 
          (#name#,#password#) 
</insert>

 

第二种:

@Repository("empMapper")
public interface EmpMapper {

  @Insert("insert into EMP(EMPNO,ENAME,HIREDATE,SAL) values (#{empno},#{ename},#{hiredate},#{sal})")
  @SelectKey(statement="select seq1.nextval from dual",
    keyProperty="empno",resultType=int.class,before=true)
  int add(Emp emp);

}

 

posted @ 2016-11-01 23:34  萌哒哒~  阅读(4163)  评论(0编辑  收藏  举报