java - mybatis查询不到数据,而直接执行SQL可以执行?
伊谢尔伦
伊谢尔伦 2017-04-17 18:01:23
0
7
594

如题,结果如下:

程序查询的输出:

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)

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


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

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回覆(7)
伊谢尔伦

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
黄舟

簡單,中文亂碼的問題

迷茫

連接資料庫位址後面加上?autoReconnect=true&useUnicode=true&characterEncoding=utf8

洪涛

應該是mybatis的配置問題,差不多是出現在like附近,可以這麼搞:like CONCAT('%',#{XXX},'%')

Ty80

雷雷

大家讲道理

我猜也是編碼問題

PHPzhong

http://blog.csdn.net/michaelj...
參考這個連結或許會帶給你靈感

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!