错误信息:java.lang.RuntimeException: com.jfinal.plugin.activerecord.ActiveRecordException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 20' at line 5
代码:
public Page<Record> getUnreadList(String uid, Integer pageNum){ SqlPara sqlPara = dbo().getSqlPara("getUnreadList", Kv.by("uid", uid)); return dbo().paginate(pageNum, 20, sqlPara); }
然而,换成不分页的方式就没有问题:
public List<Record> getList(String uid){ SqlPara sqlPara = dbo().getSqlPara("getUnreadList", Kv.by("uid", uid)); return dbo().find(sqlPara); }
其中的 dbo() 是父类提供的 Db.use(...) 对象
原SQL:
#sql("getUnreadList") SELECT rec.id, rec.reciveId, rec.reciveName, sub.mtype, sub.content, sub.senderId, sub.senderName, sub.cdate FROM msg_recive rec INNER JOIN msg_subject sub on sub.id = rec.subjectId WHERE rec.reciveId = #para(uid) and rec.readed = 0; #end
看到老大的回复,将SQL修改成带括号的形式:
#sql("getUnreadList") SELECT * FROM ( SELECT rec.id, rec.reciveId, rec.reciveName, sub.mtype, sub.content, sub.senderId, sub.senderName, sub.cdate FROM msg_recive rec INNER JOIN msg_subject sub on sub.id = rec.subjectId WHERE rec.reciveId = #para(uid) and rec.readed = 0 ) temp; #end
之后还是出错,错误提示跟上面的一样
把整个语句复制到数据库执行没问题
项目:JFinal
http://www.jfinal.com/doc/5-6