- xml中写法:
<!-- 添加一条信息数据 -->
<insert id="add" parameterType="com.hgcbys.bean.PostGraduate" useGeneratedKeys="true" keyProperty="id">
INSERT INTO post_graduate ......
</insert>
主要在Insert标签中加入:useGeneratedKeys=“true” keyProperty=“id”
- Controller中写法。
//添加一条数据,postGraduate为添加的数据对象
studentPostService.createStudentPost(postGraduate);
//主要为以下此行(postGraduate即为刚刚添加的数据对象)
Integer id= postGraduate.id(); //id即为新增数据的主键id