postgresql + mybatis插入记录时设置自增主键方法:

一、数据库设置主键自增

1.数据库中id字段选择serial4类型后,会在默认值中生成 nextval('app_id_seq'::regclass),即从序列中取下一个值

2.在AppDO类中包含字段:id,app_id,app_name

3.在mapper.xml中设置insert语句:

<insert id="insert" parameterType="appdo">
insert into app
(app_id,app_name,create_time,modify_time)
values
( #{appId}, #{appName}, now(), now() )
</insert>

也可以像下面这样:

<insert id="insert" parameterType="appdo" >
<selectKey keyProperty="id" resultType="int" order="BEFORE">
SELECT nextval('app_id_seq'::regclass) as id
</selectKey>
insert into app (id, app_id,app_name,create_time,modify_time)
values (#{id},#{app_id},#{app_name},now(),now())
</insert>

都能实现主键自增。

postgresql + mybatis insert主键自增方法的更多相关文章

  1. 【mybatis】mybatis中insert 主键自增和不自增的插入情况【mysql】

    主键不自增:返回值是插入的条数 <insert id="add" parameterType="EStudent"> insert into TSt ...

  2. Mybatis设置主键自增

    <insert id="insertArea" useGeneratedKeys="true" keyProperty="areaId" ...

  3. mysql的myBatis,主键自增设置

    方法一: insert id="insert" parameterType="Person" useGeneratedKeys="true" ...

  4. postgresql如何让主键自增

    法一: Sql代码 收藏代码 CREATE TABLE customers ( customerid SERIAL primary key , companyname character varyin ...

  5. postgresql 如何设置主键自增

    法一: CREATE TABLE customers ( customerid SERIAL primary key , companyname character varying, contactn ...

  6. mybatis-plus 主键自增问题

    主键不自增:返回值是插入的条数 <insert id="add" parameterType="EStudent"> insert into TSt ...

  7. MyBatis返回主键,MyBatis Insert操作返回主键

    MyBatis返回主键,MyBatis Insert操作返回主键 >>>>>>>>>>>>>>>>> ...

  8. MyBatis插入记录时返回主键id的方法

    有时候插入记录之后需要使用到插入记录的主键,通常是再查询一次来获取主键,但是MyBatis插入记录时可以设置成返回主键id,简化操作,方法大致有两种. 对应实体类: public class User ...

  9. Spring中新建记录后返回自增主键的处理方法

    接手一个旧系统改造的过程,要插入后立即返回自增值,不能重构guid类型主键,Spring提供了很优美的机制. Spring利用GeneratedKeyHolder,提供了一个可以返回新增记录对应主键值 ...

随机推荐

  1. c# 图片带水纹波动

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. yarn install npm install (转载)

    解决 npm i 及 yarn install 都无法进行安装的问题和node-sass安装太慢的问题 2018年03月31日 19:49:07 Johnny丶me 阅读数:2906更多 所属专栏:  ...

  3. [PHP] 多进程通信-消息队列使用

    向消息队列发送数据和获取数据的测试 <?php $key=ftok(__FILE__,'a'); //获取消息队列 $queue=msg_get_queue($key,0666); //发送消息 ...

  4. Itween 动画插件中 的画线

    1.首先在你的层次视图中创建所需的节点 ,节点的位置顺序排列 2.导入Itween 插件 1.可以直接从项目外部拖拽到本项目中 2.通过AssetStore 中导入 3.在你的父节点上创建脚本 ,对象 ...

  5. 网页导航栏 html + css的代码实现

    一般来讲,我们的网页导航栏是这么个模式来构建在结构上:1.首先我们需要给导航栏的div 给个类名 一般为nav2.然后就是一个无序表格 3.由于导航栏的文字一般都是链接用来跳转页面 要在li里面包含一 ...

  6. CSS3属性animation-play-state控制动画运行或暂停的技巧

    animation-play-state介绍 animation-play-state 属性规定动画正在运行还是暂停. div{ animation-play-state:paused; -webki ...

  7. 通过 python ssh库连接并发送命令给设备

    import paramiko import time hostname = '192.168.248.156' port = 22 user = 'zhou' passwd = ' paramiko ...

  8. Android为TV端助力 fragment 的用法以及与activity的交互和保存数据的方法,包括屏幕切换(转载)!

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37992017 1.管理Fragment回退栈 类似与Android系统为Acti ...

  9. How do I install Daydream on my phone?

    Google's philosophy with their newest VR platform is simple. In order to offer the best possible exp ...

  10. 使用git将Android源码上传到github

    下面举Android的Browser源码通过git保存到github上 首先在github.com官网new repository一个仓库 在Repository name哪里填入Browser然后创 ...