MyBatis Plus自定义sql结合多个wrapper的解决方案
MyBatis Plus自定义sql结合多个wrapper的解决方案
·
MyBatis Plus自定义sql结合多个wrapper的解决方案
service
// begin end
LambdaQueryWrapper<Folder> endWp = commonWp.clone();
LambdaQueryWrapper<Folder> beginWp = commonWp.clone();
endWp.eq(Folder::getName, folderNameArr.get(folderNameArr.size() - 1));
beginWp.eq(Folder::getName, folderNameArr.get(0));
// 多申明两个传参,替换掉默认的ew占位符
String endWpstr = endWp.getCustomSqlSegment().replaceAll("ew", "endWp");
String beginWpstr = beginWp.getCustomSqlSegment().replaceAll("ew", "beginWp");
List<Folder> result = folderMapper.queryTreeListByFolderNames(endWp, beginWp, endWpstr, beginWpstr);
dao
@Select(value = {
"WITH RECURSIVE resEnd AS (\n" +
" SELECT * FROM public.technical_folder ${endWpstr}\n" +
" UNION ALL\n" +
" SELECT b.* FROM resEnd a INNER JOIN public.technical_folder b ON a.parent_id = b.id\n" +
"),resBegin AS (\n" +
" SELECT * FROM public.technical_folder ${beginWpstr}\n" +
" UNION ALL\n" +
" SELECT b.* FROM resBegin a INNER JOIN resEnd b ON a.id = b.parent_id\n" +
")SELECT a.* from resEnd a INNER JOIN resBegin b ON a.id = b.id ORDER BY a.level"
})
List<Folder> queryTreeListByFolderNames(@Param("endWp") Wrapper<Folder> endWp,
@Param("beginWp") Wrapper<Folder> beginWp,
@Param("endWpstr") String endWpstr,
@Param("beginWpstr") String beginWpstr);
更多推荐
已为社区贡献1条内容
所有评论(0)