日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

MyBatis-plus wrapper.and用法 | apply

作者:m0_59259076 更新時間: 2023-10-11 編程語言

MyBatis-plus 通過 wrapper.and方法給sql添加額外的查詢條件

MyBatis-plus方法:
    public Children and(boolean condition, Consumer<Children> consumer) {
        return this.and(condition).addNestedCondition(condition, consumer);
    }

一、需求:如果用戶穿插了查詢參數(shù),就給sql附加條件(當(dāng)然,這個條件可以是復(fù)雜的條件),否則查詢不用帶上條件。

示例:

    @org.junit.Test
    public void test() {
        String name = "狗哥";
        QueryWrapper<Animal> wrapper = new QueryWrapper<>();
        wrapper.and(StringUtils.isNotBlank(name),item->item.apply(
                "FIND_IN_SET({0},name)",name));
        List<Animal> animalList = animalMapper.selectList(wrapper);
        log.info("總記錄:{}",animalList.size());
        animalList.forEach(System.out::println);
    }

一、需求:如果用戶穿插了查詢參數(shù),就給sql附加條件(當(dāng)然,這個條件可以是復(fù)雜的條件),否則查詢其他的條件。

    default Children and(Consumer<Param> consumer) {
        return this.and(true, consumer);
    }
    @org.junit.Test
    public void test() {
        String name = "";
        QueryWrapper<Animal> wrapper = new QueryWrapper<>();
        wrapper.and(item->item.apply(
                "FIND_IN_SET({0},name)",name).or().eq("name","貓哥"));
        List<Animal> animalList = animalMapper.selectList(wrapper);
        log.info("總記錄:{}",animalList.size());
        animalList.forEach(System.out::println);
    }
 wrapper.apply("(receipt_no Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or customer Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or matter Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or bill_unit Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or receipt_money Like '%"+incomeCollectionReceipt.getSearchValue()+"%' or item_name Like '%"+incomeCollectionReceipt.getSearchValue()+"%')");

原文鏈接:https://blog.csdn.net/m0_59259076/article/details/125120100

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新