springboot mybatis如何获取到Select中的Total

Niubist_ 2018-10-09 08:15:26
如何获取到下面日志中的Total值?


Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1ee0ce01] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1074140783 wrapping com.mysql.jdbc.JDBC4Connection@75ea7a43] will not be managed by Spring
==> Preparing: select * from futao_user where mobile like '%%' order by createtime desc limit ?,?
==> Parameters: 0(Integer), 11(Integer)
<== Columns: id, username, age, mobile, email, address, createtime, lastmodifytime
<== Row: 5383a739b1a24e01848d432e4afe241e, 111, 1, 111, 1@qq.com, 1, 2018-10-09 16:33:48.0, 2018-10-09 16:33:48.0
<== Row: 5894375f594f4b439e77111299d3d379, 222, 2, 222, 2@qq.com, 2, 2018-10-09 16:33:41.0, 2018-10-09 16:33:41.0
<== Row: b3d6d3b48a48406eb1d70ae6daaa2d5e, 333, 3, 333, 3@qq.com, 3, 2018-10-09 16:33:28.0, 2018-10-09 16:33:28.0
<== Row: 7c4e588233534398a7b21c9fc907556c, 444, 4, 444, 5@qq.com, 5, 2018-10-09 16:33:10.0, 2018-10-09 16:33:10.0
<== Row: bc3882a3e5e44d3c922c2ef0d15bab3a, 555, 5, 5, 5@qq.com, 5, 2018-10-09 16:32:57.0, 2018-10-09 16:27:53.0
<== Total: 5
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1ee0ce01]



代码:

@Select("select " +
"* " +
"from futao_user " +
"where mobile like '%${mobile}%' " +
"order by createtime desc " +
"limit #{start},#{limit}")
List<User> list(@Param("mobile") String mobile, @Param("start") int start, @Param("limit") int limit);
显示sql的配置:
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
...全文
491 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱_LOVE 2018-10-10
  • 打赏
  • 举报
回复
最简单的就是改下sql:select count(1) as total,* from..............后面记得group by,然后直接获取total就是

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧