使用 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);
}
阅读 4974 · 发布于 2020-04-25
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Android 一键清理用户数据阅读 2778
-
Spring 依赖注入原理阅读 1536
-
PostgreSQL 查看数据库配置信息阅读 179
-
Nginx 配置之反向代理获取真实 IP阅读 3275
-
软考-系统架构设计师:数据库故障与恢复阅读 1633
-
PostgreSQL 使用 \copy 命令时报 character with byte sequence 0xc3 0xa5 in encoding "UTF8" has no equivalent in encoding "GBK"阅读 9913
-
Android 底部控件不受输入法影响被顶到上方阅读 1927
-
走进 Rust:配置 IDEA 开发环境阅读 6028
-
Linux grep 过滤注释行阅读 1078
-
使用 ffmpeg 转换 m4a 为 mp3阅读 8097