Spring Boot以注解形式返回成功插入数据后的ID

mapper

@Insert("INSERT INTO collection_plan " +
            "(co_id,co_num,co_group_ids,co_content,co_start_time,co_end_time,co_status,co_plan_name,co_pids) " +
            "values " +
            "(nextval('collection_plan_seq'),#{coNum,jdbcType=VARCHAR},#{coGroupIds,jdbcType=VARCHAR},#{coContent,jdbcType=VARCHAR},#{coStartTime,jdbcType=DATE},#{coEndTime,jdbcType=DATE},'false',#{coPlanName,jdbcType=VARCHAR},#{coPids,jdbcType=VARCHAR}) " +
            "RETURNING co_id")
    @Options(useGeneratedKeys=true, keyProperty="coId", keyColumn="coId")
    void addPlanByObject(CollectionPlan collplan);
  1. sql 中 returning ID
  2. 注解添加 @Options
  3. 方法无返回值 void

service

int addPlanByObject(CollectionPlan collplan);

serviceImpl

@Override
    public int addPlanByObject(CollectionPlan collplan) {
        collmaper.addPlanByObject(collplan);
        return collplan.getCoId();
    }

猜你喜欢

转载自blog.csdn.net/weixin_42547014/article/details/108868212