七仔的博客

七仔的博客GithubPages分博

0%

Mybatis-plus子查询的一个思路

思路就是QueryWrapper中的getCustomSqlSegment()这个函数,其实在Mybatis的xml文件中${ew.customSqlSegment}的customSqlSegment也是用的这个函数

Mybatis-plus子查询的一个思路

思路

思路就是QueryWrapper中的getCustomSqlSegment()这个函数,其实在Mybatis的xml文件中${ew.customSqlSegment}的customSqlSegment也是用的这个函数,使用这个函数可以做一个小的QueryWrapper然后getCustomSqlSegment()转为字符串,最后替换其中的#{}(忘了是什么了,后面补上),然后在大的QueryWrapper里用inSql函数添加这个转换后的字符串

伪代码(后面补上完整的)

1
2
3
4
5
6
QueryWrapper<Test> queryWrapper = new QueryWrapper<>();
QueryWrapper<Test> childQueryWrapper = new QueryWrapper<>();
childQueryWrapper.eq("CESHI", value);
String childString = childQueryWrapper.getCustomSqlSegment();
childString = childString.replace("#{}", value);
queryWrapper.inSql("NEW", childString);

此为博主副博客,留言请去主博客,转载请注明出处:https://www.baby7blog.com/myBlog/85.html

欢迎关注我的其它发布渠道