吴大宝藏男孩 2018-07-02 06:40 采纳率: 50%
浏览 6306
已采纳

同一条SQL语句,myBatis查出来的数据和Navicat查出来的数据不同

通过日志打印的mybatis执行的SQL语句,原原本本复制到数据库,可以查出来很多条数据,但是mybatis要么查不到,要么少数据。
1.已尝试过写死传入参数,证明不是参数问题
2.尝试过select *,无效
3.尝试过查询的数据不小于resultMap里面的数据,也无效
4.写一个POJO类(是叫DTO吧?)来接收数据,也无效
5.SQL语句很简单,而且是通过复制到数据库,以及属性名都是通过复制,不存在写错。

走投无路了。。

以下是代码段以及日志:
日志:

 2018-07-02 14:05:00,244 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49]
2018-07-02 14:05:00,244 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction
2018-07-02 14:05:00,244 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==>  Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 
2018-07-02 14:05:00,244 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 9(Integer)
2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <==      Total: 17
2018-07-02 14:05:00,316 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49]
2018-07-02 14:05:00,316 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction
2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==>  Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 
2018-07-02 14:05:00,316 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 3(Integer)
2018-07-02 14:05:00,393 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <==      Total: 1143
2018-07-02 14:05:00,394 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49]
2018-07-02 14:05:00,394 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction
2018-07-02 14:05:00,394 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==>  Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 
2018-07-02 14:05:00,394 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 2(Integer)
2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <==      Total: 36
2018-07-02 14:05:00,472 DEBUG [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49]
2018-07-02 14:05:00,472 DEBUG [org.mybatis.spring.SqlSessionUtils] - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5f2b1d49] from current transaction
2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==>  Preparing: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ? 
2018-07-02 14:05:00,472 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - ==> Parameters: 1(Integer)
2018-07-02 14:05:00,546 DEBUG [com.talk915.liveManagement.webapp.dao.group.VideoRecordDao.getDataByRoomIdforquery] - <==      Total: 575

以最后一条查询语句为例
: select v.VideoStream videoStream,v.FileSize fileSize,v.Quality quality,v.UserType userType from vod_videorecord v where trim(v.RoomID) = ?

参数:1
返回条数:575条
数据库数据: 594条

这是差的少的情况,差的多了,直接差了几百,一千条数据都是..

数据库数据:
图片说明

mapper里面代码段:
图片说明

  • 写回答

8条回答

  • tjhdaxia 2018-07-02 07:21
    关注

    这种情况,一般是数据库链接搞错导致。请认真检查数据库链接。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料