ssm框架,往数据库插入一条数据,返回插入数据的id

若如初见. 提交于 2019-11-26 14:21:42


<insert id="preserveStudent" parameterType="com.model.Student" useGeneratedKeys="true">

insert into Student
(name,phone,grade,teacher,hobby,sex) 
values
(#{name},#{phone},#{grade},#{teacher},#{hobby},#{sex})
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
    </selectKey>
</insert>


controller写法:
studentService.preserveStudent(student);//执行service方法
int id=student.getId();//返回的id是在pojo中去取。
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!