使用 MyBatis 注解接收 PostgreSQL 的 returning 结果
MyBatis PostgreSQL 大约 958 字returning
PostgreSQL
支持在insert
/update
/delete
语句中添加returning
返回一些记录的信息。
如:插入记录后返回主键id
。
insert into t_test(column1, column2) values(value1, value2) returning id;
MyBatis
使用MyBatis
中的@Select
和@Options
两个注解完成接收(没错,增删改也用@Select
注解)。
如:以插入留言板信息为例。
@Mapper
public interface MybatisService {
@Select("insert into message_board(nickname, content, floor, ip_id, ua, os, browser, reply_id, root_id, reply_count, create_ts, update_ts) values(" +
"#{nickname}," +
"#{content}," +
"#{floor}," +
"(select id from ip_pool where ip=#{ip}::inet)," +
"#{userAgent}," +
"#{os}," +
"#{browser}," +
"#{reply_id}," +
"#{root_id}," +
"#{reply_count}," +
"#{commentTime}," +
"#{commentTime}" +
") RETURNING id")
@Options(flushCache = Options.FlushCachePolicy.TRUE)
Integer insertMessageBoard(MessageBoard messageBoard);
}
阅读 2898 · 发布于 2020-04-25
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Python UnicodeDecodeError: 'gbk' codec can't decode byte 0x80阅读 2652
-
设计模式之适配器模式阅读 1525
-
Android EditText 软键盘回车键变成搜索键阅读 1862
-
PowerShell 使用 wget 只输出信息不下载问题阅读 2536
-
MySQL 之 explain/desc type 字段阅读 1154
-
Java synchronized 锁字符串注意点阅读 2218
-
Spring Boot 整合多数据源阅读 833
-
OpenResty 中使用 lua-resty-http 完成 HTTP 请求阅读 9572
-
PHP查看配置文件所在位置阅读 939
-
PostgreSQL 备份与还原阅读 3658