JPressProjects / jpress

JPress,一个使用 Java 开发的建站神器,目前已经有 10w+ 网站使用 JPress 进行驱动,其中包括多个政府机构,200+上市公司,中科院、红+字会等。
http://www.jpress.cn
GNU Lesser General Public License v3.0
2.68k stars 1.18k forks source link

文章评论后就无法访问 #6

Closed woobai closed 8 years ago

woobai commented 8 years ago

给文章添加评论后,再次访问该文章,无法访问,后台报错

woobai commented 8 years ago
原因是Comment类中的查询语句有问题,其中40-50行可做如下修改,
        String select = " select c.*,cnt.title content_title,u.username";
        StringBuilder fromBuilder = new StringBuilder("  from comment c");
        fromBuilder.append(" left join content cnt on c.content_id = cnt.id");
        fromBuilder.append(" left join user u on c.user_id = u.id ");

        LinkedList<Object> params = new LinkedList<Object>();
        boolean needWhere = true;
        needWhere = appendIfNotEmpty(fromBuilder, "c.`type`", type, params, needWhere);
        needWhere = appendIfNotEmpty(fromBuilder, " c.content_module", module, params, needWhere);
        needWhere = appendIfNotEmpty(fromBuilder, " c.`status`", status, params, needWhere);
        needWhere = appendIfNotEmpty(fromBuilder, " cnt.id", contentId, params, needWhere);

82-86可做如下修改:

        StringBuilder sqlBuilder = new StringBuilder("select c.*,cnt.title content_title,u.username");
        sqlBuilder.append(" from comment c");
        sqlBuilder.append(" left join content cnt on c.content_id = cnt.id");
        sqlBuilder.append(" left join user u on c.user_id = u.id ");
        sqlBuilder.append(" where c.id = ?");
也可在JModel类中做如下修改
        return super.paginate(pageNumber, pageSize, tc(select), tc(sqlExceptSelect), paras);
woobai commented 8 years ago

哦,sorry,最新代码已经修改了