首页 > 代码库 > mybatis自增长插入id

mybatis自增长插入id

第一种:

<insert id="insertUser" parameterClass="ibatis.User"> 
      <selectKey resultType="long" keyProperty="id"> 
        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);

}

 

mybatis自增长插入id