MybatisPlus插件queryWrapper.last()查询报错
MybatisPlus 插件 queryWrapper.last() 是用来作 limit 限定的,我项目中 limit 的值是动态的,给出源码:
public Result hotArticle(int limit)
{
LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(Article::getViewCounts);
queryWrapper.select(Article::getId, Article::getTitle);
queryWrapper.last("limit " + limit); //这里"limit "应有空格!!!
//select id, title from article order by view_counts desc limit 5
List<Article> articles = articleMapper.selectList(queryWrapper);
return Result.success(copyList(articles, false, false));
}
一开始 "limit " 这里没有空格,直接报错
可以看见这里 limit 和 5 直接连上了,所以查询报错,只要在 "limit ",这里 limit 右边加个空格就不会报错了!