时间:2021-07-01 10:21:17 帮助过:29人阅读
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>
Mybatis处理ORACLE自增的问题(通过触发器)
标签:oracle自增、mybatis