Mybatis-Plus中使用max、sum聚合函數、只查詢指定字段、查詢語句多個OR處理


 

 

聚合函數查詢

可以使用以下方法

  QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.select("  IFNULL( max(percent),0) as maxPercent");
        Map<String, Integer> map = getMap(queryWrapper);
        return map.get("maxPercent");

 

只查詢指定字段(只查詢三個字段)

 queryWrapper.select("content_id","img_url","title")

 

排除某些字段 這表示不查詢Content實體類對應的數據庫中的content_txt字段

queryWrapper.select(
                Content.class, info ->
                        !info.getColumn().equals("content_txt")
        )

 

 

and后面跟多個or(and (or or or ))

queryWrapper.eq("id", "1");
            queryWrapper.and(wrapper -> {
                searchTitle.forEach(s -> {
                    wrapper.or().like("title", s);
                });
            });

等價 where id=1 and ( title like '%s%' or titile like '%s%');  這里的searchTitle是個集合 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM