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);

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM