Mybatis添加之后返回一个id

来源:互联网 发布:ubuntu查看mysql路径 编辑:程序博客网 时间:2024/05/21 11:20

Mybatis添加之后返回一个id有两种方法,如下


A.直接写在insert标签里

<insert id="insertRadar" parameterType="com.hhigh.business.domain.Radar" useGeneratedKeys="true" keyProperty="id">insert into t_radar (<include refid="radarAttributes" />) values (#{id},#{file_name},#{format},#{file_size},#{file_url},#{station_name},#{province},#{city},#{cnty},#{town},#{datetime},#{station_id_c},#{year},#{mon},#{day},#{hour},#{min},#{second},#{rada_model},#{scanning_mode},#{filename_orig})</insert>

B.写在插入语句下面

<insert id="insertRadar" parameterType="com.hhigh.business.domain.Radar">insert into t_radar (<include refid="radarAttributes" /> ) values (#{id},#{file_name},#{format},#{file_size},#{file_url},#{station_name},#{province},#{city},#{cnty},#{town},#{datetime},#{station_id_c},#{year},#{mon},#{day},#{hour},#{min},#{second},#{rada_model},#{scanning_mode},#{filename_orig})<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >select @@identity as id;</selectKey></insert>