使用 MyBatis 注解接收 PostgreSQL 的 returning 结果
MyBatis PostgreSQL About 958 wordsreturning
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);
}
Views: 5,985 · Posted: 2020-04-25
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...