1. Oracle数据库中创建自增序列
create sequence article_info_id_seq minvalue 1 nomaxvalue start with 1 increment by 1;
2. mybatis的mapper.xml中:
- selectKey的结果会放进传参ArticleInfo对象中
<insert id="insert" parameterType="top.zdigi.entity.ArticleInfo">
<selectKey keyProperty="articleInfoId" resultType="java.lang.Integer" order="BEFORE">
select article_info_id_seq.nextval from dual
</selectKey>
insert into ARTICLE_INFO (ARTICLE_INFO_ID, TITLE, SUMMARY,
IS_TOP, PAGE_VIEW, CREATE_BY
)
values (#{articleInfoId,jdbcType=DECIMAL}, #{title,jdbcType=VARCHAR}, #{summary,jdbcType=VARCHAR},
#{isTop,jdbcType=DECIMAL}, #{pageView,jdbcType=DECIMAL}, #{createBy,jdbcType=TIMESTAMP}
)
</insert>
网友评论