在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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。