com.baomidou.mybatisplus.mapper.Wrapper类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(346)

本文整理了Java中com.baomidou.mybatisplus.mapper.Wrapper类的一些代码示例,展示了Wrapper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wrapper类的具体详情如下:
包路径:com.baomidou.mybatisplus.mapper.Wrapper
类名称:Wrapper

Wrapper介绍

暂无

代码示例

代码示例来源:origin: stylefeng/Guns

/**
 * 删除字典
 *
 * @author fengshuonan
 * @Date 2018/12/23 5:25 PM
 */
@Transactional
public void delteDict(Long dictId) {
  //删除这个字典的子词典
  Wrapper<Dict> dictEntityWrapper = new EntityWrapper<>();
  dictEntityWrapper = dictEntityWrapper.eq("PID", dictId);
  dictMapper.delete(dictEntityWrapper);
  //删除这个词典
  dictMapper.deleteById(dictId);
}

代码示例来源:origin: stylefeng/Guns

@Override
public List<Long> getSubDeptId(Long deptId) {
  Wrapper<Dept> wrapper = new EntityWrapper<>();
  wrapper = wrapper.like("PIDS", "%[" + deptId + "]%");
  List<Dept> depts = this.deptMapper.selectList(wrapper);
  ArrayList<Long> deptids = new ArrayList<>();
  if (depts != null && depts.size() > 0) {
    for (Dept dept : depts) {
      deptids.add(dept.getDeptId());
    }
  }
  return deptids;
}

代码示例来源:origin: leecho/cola-cloud

/**
 * @param id
 * @return
 */
@Override
public List<SysOrganization> getOrganizationListByPid(Long id) {
  EntityWrapper<SysOrganization> wrapper = this.newEntityWrapper();
  //添加租户查询条件
  this.addTenantCondition(wrapper);
  if (id == null) {
    wrapper.isNull("parent");
  } else {
    wrapper.eq("parent", id);
  }
  wrapper.andNew().eq("deleted", CommonConstant.COMMON_NO).or().isNull("deleted");
  return this.selectList(wrapper);
}

代码示例来源:origin: leecho/cola-cloud

/**
 * 检查是否有重复属性的数据
 *
 * @param property
 * @param value
 * @param excludeId
 * @return
 */
public boolean checkProperty(String property, Object value, Long excludeId) {
  if (value == null || StringUtils.isEmpty(String.valueOf(value))) {
    return true;
  }
  List<SysUser> users = null;
  Wrapper<SysUser> wrapper = new EntityWrapper<SysUser>();
  wrapper.eq(property, value);
  if (excludeId != null) {
    wrapper.ne("id", excludeId);
  }
  users = this.mapper.selectList(wrapper);
  return (users.size() == 0);
}

代码示例来源:origin: com.wuyushuo/wuyu-module-stream

@Async
public Future<List<Datum>> selectDatums(long appId, List<Long> datumIds){
  if(appId <=0 || CollectionUtils.isEmpty(datumIds)){
    throw new IllegalArgumentException("参数错误");
  }
  EntityWrapper<Datum> wrapper = new EntityWrapper<Datum>();
  wrapper.eq("app_id", appId).in("id", datumIds).eq("enabled", EnableEnum.ENABLED.getValue());
  List<Datum> list = datumService.selectList(wrapper);
  return new AsyncResult<>(list);
}

代码示例来源:origin: qiurunze123/GEEKQ-CM

@Override
public void addDict(String dictCode,String dictName,String dictTips, String dictValues) {
  List<Dict> dicts = dictMapper.selectList(new EntityWrapper<Dict>().eq("code", dictCode).and().eq("pid", 0));
  if (dicts != null && dicts.size() > 0) {
    throw new GunsException(BizExceptionEnum.DICT_EXISTED);

代码示例来源:origin: watchdog-framework/watchdog-framework

@Override
public List<SysResource> list() {
  EntityWrapper<SysResource> wrapper = new EntityWrapper<>();
  wrapper.eq("parent_id",0)
      .or()
      .isNull("parent_id")
      .orderBy("sort");
  List<SysResource> resources = this.selectList(wrapper);
  if(resources!=null && resources.size()>0){
    resources.forEach(this::findAllChild);
  }
  return resources;
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

continue;
} else if (operator == Operator.isNull) {
  wrapper.isNull(property);
} else if (operator == Operator.isNotNull) {
  wrapper.isNotNull(property);
} else if (operator == Operator.between) {
  Object[] between = null;
    wrapper.between(property, between[0], between[1]);
    wrapper.notLike(filter.getProperty(), (String) value);
    wrapper.like(filter.getProperty(), (String) value);

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

@Override
public Wrapper<T> orderBy(boolean condition, String columns) {
  if (columns==null) {
    return super.orderBy(condition, columns);
  }
  String[] columnArr = columns.split(",");
  String columnNews = "";
  for (String column : columnArr) {
    if (!columnNews.isEmpty()) {
      columnNews += ",";
    }
    columnNews += handleColumn(column);
  }
  return super.orderBy(condition, columnNews);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

/**
 * <p>
 * 等同于SQL的"field <> value"表达式
 * </p>
 *
 * @param column
 * @param params
 * @return
 */
public Wrapper<T> ne(String column, Object params) {
  return super.ne(handleColumn(column), params);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

/**
 * <p>
 * is not null 条件
 * </p>
 *
 * @param condition
 *            拼接的前置条件
 * @param columns
 *            字段名称。多个字段以逗号分隔。
 * @return this
 */
public Wrapper<T> isNull(boolean condition, String columns) {
  String[] columnArr = columns.split(",");
  String columnNews = "";
  for (String column : columnArr) {
    if (!columnNews.isEmpty()) {
      columnNews += ",";
    }
    columnNews += handleColumn(column);
  }
  return super.isNull(condition, columnNews);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

private Boolean validTable(DuplicateValid duplicateValid, Wrapper<T> wrapper) {
  Integer num = null;
  String extendName = duplicateValid.getExtendName();
  String extendParam = duplicateValid.getExtendParam();
  if (!StringUtils.isEmpty(extendParam)) {
    // [2].编辑页面校验
    wrapper.eq(duplicateValid.getName(), duplicateValid.getParam()).ne(extendName, extendParam);
    num = baseMapper.selectCount(wrapper);
  } else {
    // [1].添加页面校验
    wrapper.eq(duplicateValid.getName(), duplicateValid.getParam());
    num = baseMapper.selectCount(wrapper);
  }
  if (num == null || num == 0) {
    // 该值可用
    return true;
  } else {
    // 该值不可用
    return false;
  }
}

代码示例来源:origin: com.wuyushuo/wuyu-module-stream

@Async
public Future<Boolean> deleteFavorite(long appId, long personId, List<Long> targetIds, int favoriteType) throws Exception {
  if(appId <=0 || personId<=0 || CollectionUtils.isEmpty(targetIds)){
    throw new IllegalArgumentException("参数错误");
  }
  EntityWrapper<Favorite> wp = new EntityWrapper<>();
  wp.eq("app_id", appId).eq("user_id", personId).in("target_id", targetIds).eq("type", favoriteType).eq("enabled", EnableEnum.ENABLED.getValue());
  List<Favorite> list = favoriteService.selectList(wp);
  Date now = new Date();
  Optional.ofNullable(list).orElse(Lists.newArrayList())
      .forEach(
          x -> {
            x.setEnabled(EnableEnum.DISABLE.getValue());
            x.setUpdateTime(now);
          }
      );
  boolean isOk = favoriteService.updateAllColumnBatchById(list);
  return new AsyncResult<>(isOk);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

@Override
public Wrapper<T> orderBy(boolean condition, String columns, boolean isAsc) {
  if (columns==null) {
    return super.orderBy(condition, columns, isAsc);
  }
  String[] columnArr = columns.split(",");
  String columnNews = "";
  for (String column : columnArr) {
    if (!columnNews.isEmpty()) {
      columnNews += ",";
    }
    columnNews += handleColumn(column);
  }
  return super.orderBy(condition, columnNews, isAsc);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

/**
 * <p>
 * 等同于SQL的"field <> value"表达式
 * </p>
 *
 * @param condition
 *            拼接的前置条件
 * @param column
 * @param params
 * @return
 */
public Wrapper<T> ne(boolean condition, String column, Object params) {
  return super.ne(condition, handleColumn(column), params);
}

代码示例来源:origin: stylefeng/Guns

@Override
public String getDictsByName(String name, String code) {
  Dict temp = new Dict();
  temp.setName(name);
  Dict dict = dictMapper.selectOne(temp);
  if (dict == null) {
    return "";
  } else {
    Wrapper<Dict> wrapper = new EntityWrapper<>();
    wrapper = wrapper.eq("PID", dict.getDictId());
    List<Dict> dicts = dictMapper.selectList(wrapper);
    for (Dict item : dicts) {
      if (item.getCode() != null && item.getCode().equals(code)) {
        return item.getName();
      }
    }
    return "";
  }
}

代码示例来源:origin: stylefeng/Guns

/**
 * 删除菜单包含所有子菜单
 *
 * @author stylefeng
 * @Date 2017/6/13 22:02
 */
@Transactional
public void delMenuContainSubMenus(Long menuId) {
  Menu menu = menuMapper.selectById(menuId);
  //删除当前菜单
  delMenu(menuId);
  //删除所有子菜单
  Wrapper<Menu> wrapper = new EntityWrapper<>();
  wrapper = wrapper.like("PCODES", "%[" + menu.getCode() + "]%");
  List<Menu> menus = menuMapper.selectList(wrapper);
  for (Menu temp : menus) {
    delMenu(temp.getMenuId());
  }
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

@Override
  public Wrapper<T> orderBy(String columns) {
    if (columns==null) {
      return super.orderBy(columns);
    }
    String[] columnArr = columns.split(",");
    String columnNews = "";
    for (String column : columnArr) {
      if (!columnNews.isEmpty()) {
        columnNews += ",";
      }
      columnNews += handleColumn(column);
    }
    return super.orderBy(columnNews);
  }
}

代码示例来源:origin: watchdog-framework/watchdog-framework

@Override
public void update(String id, UserUpdateDTO updateDTO) {
  SysUser user = this.selectById(id);
  if(user==null){
    throw RequestException.fail(
        String.format("更新失败,不存在ID为 %s 的用户",id));
  }
  SysUser findUser = this.selectOne(new EntityWrapper<SysUser>()
        .eq("username",updateDTO.getUsername()).ne("id",id));
  if(findUser!=null){
    throw RequestException.fail(
        String.format("更新失败,已经存在用户名为 %s 的用户",updateDTO.getUsername()));
  }
  BeanUtils.copyProperties(updateDTO,user);
  try {
    this.updateById(user);
    this.updateUserRole(user);
    shiroService.clearAuthByUserId(user.getId(),true,false);
  }catch (RequestException e){
    throw RequestException.fail(e.getMsg(),e);
  }catch (Exception e){
    throw RequestException.fail("用户信息更新失败",e);
  }
}

代码示例来源:origin: leecho/cola-cloud

@Override
public boolean exists(Long resourceId, Long roleId) {
  Wrapper<SysAuthority> wrapper = new EntityWrapper<SysAuthority>();
  wrapper.eq("sys_resource_id", resourceId);
  wrapper.eq("sys_role_id", roleId);
  return CollectionUtils.isEmpty(this.selectList(wrapper));
}

相关文章