sql语句直接在sqlyog中查询,有20几条数据,但是通过mybatis查询出来,只有5条数据,这是什么情况?
以下是我写的sql语句:
SELECT w.id id,
d.name
NAME,
d.type TYPE,
d.department department,
d.electronic_id electronicId,
w.wType wType,
w.msg msg,
d.plate_number plateNumber,
d.device_serial deviceSerial,
w.wTime wTime
FROM warning w
INNER JOIN driver d ON w.code = d.device_serial
WHERE 1 = 1
and DATE_FORMAT(w.wTime, '%Y%m%d') = #{time}
ORDER BY id DESC
可能和 and DATE_FORMAT(w.wTime, '%Y%m%d') = #{time} 这个判断有关。
使用mybatis的时候把语句打印出来看看?
SELECT w.id id, d.name
NAME, d.type TYPE, d.department department, d.electronic_id electronicId, w.wType wType, w.msg msg, d.plate_number plateNumber, d.device_serial deviceSerial, w.wTime wTime FROM warning w INNER JOIN driver d ON w.code = d.device_serial WHERE 1 = 1 and DATE_FORMAT(w.wTime, '%Y%m%d') = ? ORDER BY id DESC
打印出来是这个样子的
@xx_1234:
使用 等号(=) 比较?
还是使用 between 比较?
DATE_FORMAT(w.wTime,'%Y%m%d') = 20210910 是转化成了String类型的日期2021-09-10
@快乐的凡人721: 等号
@xx_1234:
感谢园豆。解决了吗?
可以试试打开 MySQL服务器的 普通日志 general_log 设置为 ON
然后看看 每条语句 到底是什么
包括 mybatis 过来的。
mysql> set global general_log = ON;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> show variables like '%general%';
+------------------+-----------------------------------+
| Variable_name | Value |
+------------------+-----------------------------------+
| general_log | ON |
| general_log_file | /var/lib/mysql/ben-VirtualBox.log |
+------------------+-----------------------------------+
2 rows in set (0.01 sec)