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

同一条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条)

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao