Heim  >  Fragen und Antworten  >  Hauptteil

java - mybatis查询不到数据,而直接执行SQL可以执行?

如题,结果如下:

程序查询的输出:

DEBUG queryCompany:145 - ==>  Preparing: SELECT b.id, b.name, b.average, COUNT(*) as times FROM (SELECT id, name, average from baseinfo WHERE id = ? or name LIKE ? ORDER BY average DESC LIMIT ?, ?) as b LEFT JOIN detailinfo AS d ON (b.id = d.id) GROUP BY b.id 
DEBUG queryCompany:145 - ==> Parameters: 江(String), %江%(String), 0(Integer), 6(Integer)
DEBUG queryCompany:145 - <==      Total: 0

然后我把这个sql语句直接放到数据库里查询,结果如下:

MariaDB [stock]> SELECT b.id, b.name, b.average, COUNT(*) as times FROM
    ->   (SELECT id, name, average
    ->    from baseinfo WHERE id = "江" or name LIKE "%江%"
    ->    ORDER BY average DESC LIMIT 0, 6) as b
    ->   LEFT JOIN detailinfo AS d ON (b.id = d.id)
    -> GROUP BY b.id;
+--------+--------------+------------+-------+
| id     | name         | average    | times |
+--------+--------------+------------+-------+
| 600418 | 江淮汽车     | 0.99999999 |     8 |
| 601313 | 江南嘉捷     | 0.16716038 |    10 |
+--------+--------------+------------+-------+
2 rows in set (0.00 sec)

之前都还能正常查询的,求问这是怎么回事


数据库挂掉了,还没恢复,所以没法测试是不是各位提的问题。。恢复后我会第一时间测试的

伊谢尔伦伊谢尔伦2764 Tage vor599

Antworte allen(7)Ich werde antworten

  • 伊谢尔伦

    伊谢尔伦2017-04-17 18:03:23

    Mybatis的配置问题吧,我猜可能是#号和$的问题,不知道你的配置是不是这么写的

    SELECT b.id, b.name, b.average, COUNT(*) as times FROM (SELECT id, name, average from baseinfo WHERE id = #{id} or name LIKE #{name} ORDER BY average DESC LIMIT #{}, #{}) as b LEFT JOIN detailinfo AS d ON (b.id = d.id) GROUP BY b.id

    Antwort
    0
  • 黄舟

    黄舟2017-04-17 18:03:23

    简单,中文乱码的问题

    Antwort
    0
  • 迷茫

    迷茫2017-04-17 18:03:23

    连接数据库地址后面加上?autoReconnect=true&useUnicode=true&characterEncoding=utf8

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-17 18:03:23

    应该是是mybatis的配置问题,差不多是出现在like附近,可以这么搞:like CONCAT('%',#{XXX},'%')

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-17 18:03:23

    你数据库层面是不是用了cobar或者TDDL   分库分表的中间件啊??

    Antwort
    0
  • 大家讲道理

    大家讲道理2017-04-17 18:03:23

    我猜也是编码问题

    Antwort
    0
  • PHPz

    PHPz2017-04-17 18:03:23

    http://blog.csdn.net/michaelj...
    参考这个链接或许会给你带来灵感

    Antwort
    0
  • StornierenAntwort