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