您好,登錄后才能下訂單哦!
在oracle中創建序列語句并執行:
create sequence user_seq start with 1 increment by 1;
create or replace trigger user_trigger before insert on tb_user for each row begin select user_seq.nextval into :new.id from dual; end ;
2.然后在mybatis的mapper配置文件中插入一條記錄時就不用指定id
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.cn.mapper.UserMapper"> <insert id="save" parameterType="com.cn.domain.User" useGeneratedKeys="true"> INSERT INTO TB_USER(name,sex,age) VALUES(#{name},#{sex},${age}) </insert> </mapper>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。