吴大宝藏男孩 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条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog