mybatis主键返回语句 使用方法,就是实体类.getid即可拿到返回的id

 

<insert id="insertSelective" parameterType="com.o2o.Content"
        useGeneratedKeys="true" keyProperty="id">
        insert into notice_ncontent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="vid != null">
                vid,
            </if>
            <if test="ntype != null">
                ntype,
            </if>
            <if test="canentry != null">
                canentry,
            </if>
            <if test="title != null">
                title,
            </if>
            <if test="ispush != null">
                ispush,
            </if>
            <if test="entrycount != null">
                entrycount,
            </if>
            <if test="isvalid != null">
                isvalid,
            </if>
            <if test="content != null">
                content,
            </if>
            <if test="ctime != null">
                ctime,
            </if>
            <if test="cuserid != null">
                cuser,
            </if>
            <if test="stick != null">
                stick,
            </if>
            <if test="limitcount != null">
                limitcount,
            </if>
            <if test="description != null">
                description,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="vid != null">
                #{vid,jdbcType=INTEGER},
            </if>
            <if test="ntype != null">
                #{ntype,jdbcType=TINYINT},
            </if>
            <if test="canentry != null">
                #{canentry,jdbcType=TINYINT},
            </if>
            <if test="title != null">
                #{title,jdbcType=VARCHAR},
            </if>
            <if test="ispush != null">
                #{ispush,jdbcType=TINYINT},
            </if>
            <if test="entrycount != null">
                #{entrycount,jdbcType=INTEGER},
            </if>
            <if test="isvalid != null">
                #{isvalid,jdbcType=INTEGER},
            </if>
            <if test="content != null">
                #{content,jdbcType=LONGVARCHAR},
            </if>
            <if test="ctime != null">
                #{ctime,jdbcType=BIGINT},
            </if>
            <if test="cuserid != null">
                #{cuserid,jdbcType=INTEGER},
            </if>
            <if test="stick != null">
                #{stick,jdbcType=INTEGER},
            </if>
            <if test="limitcount != null">
                #{limitcount,jdbcType=INTEGER},
            </if>
            <if test="description != null">
                #{description,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>

通过上叙就可以获取自动主键,但是一般开发中都是自己生产主键进行开发,这个是利用数据库自增主键来进行的

posted @ 2019-02-03 11:14  菩提树下的丁春秋  阅读(981)  评论(0编辑  收藏  举报