Java Code Examples for tk.mybatis.mapper.entity.Example#Criteria
The following examples show how to use
tk.mybatis.mapper.entity.Example#Criteria .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoodsService.java From leyou with Apache License 2.0 | 6 votes |
/** * 通过spu_id删除tb_sku * 通过sku_id删除tb_stock * * @param spuId */ private void deleteSkuAndStock(Long spuId) { // 通过spu_id查询sku Sku querySku = new Sku(); querySku.setSpuId(spuId); List<Sku> skus = this.skuMapper.select(querySku); // 删除sku if (!CollectionUtils.isEmpty(skus)) { // 获得sku_id集合 List<Long> ids = skus.stream().map(sku -> sku.getId()).collect(Collectors.toList()); // 通过sku_id删除tb_stock Example example = new Example(Stock.class); Example.Criteria criteria = example.createCriteria(); criteria.andIn("skuId", ids); this.stockMapper.deleteByExample(example); } // 删除sku this.skuMapper.delete(querySku); }
Example 2
Source File: UacMenuCommonController.java From paascloud-master with Apache License 2.0 | 6 votes |
/** * 检测菜单URL唯一性 * * @param uacMenuCheckUrlDto the uac menu check url dto * * @return the wrapper */ @PostMapping(value = "/checkMenuUrl") @ApiOperation(httpMethod = "POST", value = "检测菜单URL唯一性") public Wrapper<Boolean> checkUacMenuUrl(@ApiParam(name = "uacMenuCheckUrlDto", value = "id与url") @RequestBody UacMenuCheckUrlDto uacMenuCheckUrlDto) { logger.info("检测菜单URL唯一性 uacMenuCheckUrlDto={}", uacMenuCheckUrlDto); Long id = uacMenuCheckUrlDto.getMenuId(); String url = uacMenuCheckUrlDto.getUrl(); Example example = new Example(UacMenu.class); Example.Criteria criteria = example.createCriteria(); if (id != null) { criteria.andNotEqualTo("id", id); } criteria.andEqualTo("url", url); int result = uacMenuService.selectCountByExample(example); return WrapMapper.ok(result < 1); }
Example 3
Source File: UacActionCommonController.java From paascloud-master with Apache License 2.0 | 6 votes |
/** * 检测权限URL唯一性 * * @param uacActionCheckUrlDto the uac action check url dto * * @return the wrapper */ @PostMapping(value = "/checkUrl") @ApiOperation(httpMethod = "POST", value = "检测权限URL唯一性") public Wrapper<Boolean> checkActionUrl(@ApiParam(name = "uacActionCheckUrlDto", value = "id与url") @RequestBody UacActionCheckUrlDto uacActionCheckUrlDto) { logger.info("检测权限URL唯一性 uacActionCheckUrlDto={}", uacActionCheckUrlDto); Long id = uacActionCheckUrlDto.getActionId(); String url = uacActionCheckUrlDto.getUrl(); Example example = new Example(UacAction.class); Example.Criteria criteria = example.createCriteria(); if (id != null) { criteria.andNotEqualTo("id", id); } criteria.andEqualTo("url", url); int result = uacActionService.selectCountByExample(example); return WrapMapper.ok(result < 1); }
Example 4
Source File: UacUserCommonController.java From paascloud-master with Apache License 2.0 | 6 votes |
/** * 校验登录名唯一性. * * @param checkLoginNameDto the check login name dto * * @return the wrapper */ @PostMapping(value = "/checkLoginName") @ApiOperation(httpMethod = "POST", value = "校验登录名唯一性") public Wrapper<Boolean> checkLoginName(@ApiParam(name = "loginName", value = "登录名") @RequestBody CheckLoginNameDto checkLoginNameDto) { logger.info("校验登录名唯一性 checkLoginNameDto={}", checkLoginNameDto); Long id = checkLoginNameDto.getUserId(); String loginName = checkLoginNameDto.getLoginName(); Example example = new Example(UacUser.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("loginName", loginName); if (id != null) { criteria.andNotEqualTo("id", id); } int result = uacUserService.selectCountByExample(example); return WrapMapper.ok(result < 1); }
Example 5
Source File: BizArticleServiceImpl.java From OneBlog with GNU General Public License v3.0 | 6 votes |
@Override @Transactional(rollbackFor = Exception.class) public boolean removeByPrimaryKey(Long primaryKey) { boolean result = bizArticleMapper.deleteByPrimaryKey(primaryKey) > 0; // 删除标签记录 Example tagsExample = new Example(BizArticleTags.class); Example.Criteria tagsCriteria = tagsExample.createCriteria(); tagsCriteria.andEqualTo("articleId", primaryKey); bizArticleTagsMapper.deleteByExample(tagsExample); // 删除查看记录 Example lookExample = new Example(BizArticleLook.class); Example.Criteria lookCriteria = lookExample.createCriteria(); lookCriteria.andEqualTo("articleId", primaryKey); bizArticleLookMapper.deleteByExample(lookExample); // 删除赞记录 Example loveExample = new Example(BizArticleLove.class); Example.Criteria loveCriteria = loveExample.createCriteria(); loveCriteria.andEqualTo("articleId", primaryKey); bizArticleLoveMapper.deleteByExample(loveExample); return result; }
Example 6
Source File: CommentServiceImpl.java From gpmall with Apache License 2.0 | 6 votes |
@Override public DeleteCommentResponse deleteComment(DeleteCommentRequest request) { DeleteCommentResponse response = new DeleteCommentResponse(); try { request.requestCheck(); String commentId = request.getCommentId(); Comment comment = commentMapper.selectByPrimaryKey(commentId); if (comment == null || !comment.getIsDeleted()) { throw new CommentException(CommentRetCode.CURRENT_COMMENT_NOT_EXIST.getCode(), CommentRetCode.CURRENT_COMMENT_NOT_EXIST.getMessage()); } comment.setDeletionUserId(request.getUserId()); comment.setIsDeleted(true); comment.setDeletionTime(new Date()); Example example = new Example(CommentPicture.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("commentId", commentId); commentPictureMapper.deleteByExample(example); response.setCode(CommentRetCode.SUCCESS.getCode()); response.setMsg(CommentRetCode.SUCCESS.getMessage()); } catch (Exception e) { ExceptionProcessorUtil.handleException(response, e); } return response; }
Example 7
Source File: SysDictService.java From easyweb with Apache License 2.0 | 6 votes |
public String update(SysDict model, String userId) { String result = "成功!"; model.setDescription(model.getRemarks()); if ("0".equals(model.getParentId())) { model.setType(model.getValue()); } else { SysDict pDict = mapper.selectByPrimaryKey(model.getParentId()); model.setType(pDict.getValue()); } model.setUpdateBy(userId); if (StringUtils.isEmpty(model.getId())) { model.setCreateBy(userId); model.setId(model.getValue()); if (mapper.existsWithPrimaryKey(model)) { result = "该字典值已经存在!"; } else { this.insert(model); } } else { Example example = new Example(SysDict.class); Example.Criteria criteria = example.createCriteria(); criteria.andNotEqualTo("id", model.getId()); this.updateByPrimaryKeySelective(model); } return result; }
Example 8
Source File: PageHelperTest.java From cjs_ssms with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IOException { SqlSession sqlSession = MybatisHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); /*rowBounds*/ RowBounds rowBounds = new RowBounds(2, 5); /*Example*/ Example example = new Example(Country.class); Example.Criteria criteria = example.createCriteria(); // criteria.andCountrycodeBetween("0", "ZZZZZZZZZZ"); // criteria.andIdBetween(0, 20); List<Country> countries1 = countryMapper.selectByExample(example); log.debug("countries1" + countries1.size()); List<Country> countries2 = countryMapper.selectByExampleAndRowBounds(example, rowBounds); log.debug("countries2" + countries2.size()); PageInfo<Country> pageInfo = new PageInfo<>(countries1); System.out.println("PageHelperTest.main() pageInfo :" + pageInfo.getSize()); }
Example 9
Source File: MyUserDetailsService.java From wangsy-january with Apache License 2.0 | 6 votes |
@Override public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { Example example = new Example(Merchant.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("mobile", s); if(StringUtils.isEmpty(s)) { throw new UsernameNotFoundException("手机号码不能为空"); } List<Merchant> merchants = merchantMapper.selectByCondition(example); if(CollectionUtils.isEmpty(merchants) || merchants.size()>1) { throw new UsernameNotFoundException("不存在该用户"); } User user = new User(merchants.get(0).getMobile(), merchants.get(0).getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin")); return user; }
Example 10
Source File: DictController.java From easyweb with Apache License 2.0 | 6 votes |
/** * 获取所有字典列表 * @param model * @return */ @PostMapping("/index") @ResponseBody public Page<SysDict> index(HttpServletRequest request, HttpServletResponse response, SysDict model) { Page<SysDict> pg = new Page<SysDict>(request, response,-1); Example example = new Example(SysDict.class); Example.Criteria criteria = example.createCriteria(); if (!StringUtils.isEmpty(model.getLabel())) { criteria.andLike("label", "%" + model.getLabel() + "%"); } if (StringUtils.isEmpty(model.getParentId())) { criteria.andEqualTo("parentId","0");//获取公司 }else { criteria.andEqualTo("parentId",model.getParentId()); } pg = service.selectPageByExample(example, pg); return pg; }
Example 11
Source File: BaseService.java From springboot-seed with MIT License | 5 votes |
/** * 根据字段(ID列表)获取实例列表 * * @param type 字段 * @param ids ID列表 * @return 实例列表 */ public List<T> selectAll(String type, List<Long> ids) { if (ids.isEmpty()) { return new ArrayList<>(); } else { Example example = new Example(getActualClass()); example.setOrderByClause("id desc"); Example.Criteria criteria = example.createCriteria(); criteria.andIn(type, ids); return mapper.selectByExample(example); } }
Example 12
Source File: ProductsServiceImpl.java From wangsy-january with Apache License 2.0 | 5 votes |
@Override public List<Products> selectByConditions(ProductsValid valid) { Example example = new Example(Products.class); Example.Criteria criteria = example.createCriteria(); /** * 查询未被删除的数据 */ criteria.andEqualTo("beenDeleted", false); return productsMapper.selectByCondition(example); }
Example 13
Source File: OrderServiceImpl.java From wangsy-january with Apache License 2.0 | 5 votes |
@Override public List<Order> selectByConditions(OrderValid valid) { Example example = new Example(Order.class); Example.Criteria criteria = example.createCriteria(); /** * 查询未被删除的数据 */ criteria.andEqualTo("beenDeleted", false); return orderMapper.selectByCondition(example); }
Example 14
Source File: OrderItemsServiceImpl.java From wangsy-january with Apache License 2.0 | 5 votes |
@Override public List<OrderItems> selectByConditions(OrderItemsValid valid) { Example example = new Example(OrderItems.class); Example.Criteria criteria = example.createCriteria(); /** * 查询未被删除的数据 */ criteria.andEqualTo("beenDeleted", false); return orderItemsMapper.selectByCondition(example); }
Example 15
Source File: GemPermissionsServiceImpl.java From gem with MIT License | 5 votes |
/** * @Description: 根据角色和菜单获取权限-按钮(包含未选中) * @param roleId 角色主键 * @param permissionId 权限(菜单)主键 * @author: Ryan * @date 2018年11月5日 */ @Override public List<GemPermissions> findPermissionSelectByRoleIdAndPermissionId(Long roleId,Long permissionId) { List<GemPermissions> permissionButtonListByPermissionId = new ArrayList<GemPermissions>(); if(roleId != null){ //根据菜单获取对应的按钮 Example example = new Example(GemPermissions.class); Example.Criteria createCriteria = example.createCriteria(); createCriteria.andEqualTo("menusType",1); createCriteria.andEqualTo("parentId",permissionId); example.setOrderByClause("per_sort asc"); permissionButtonListByPermissionId = permissionsMapper.selectByExample(example); //根据菜单和角色获取对应的按钮 Map<String, Object> hashMap = new HashMap<String,Object>(); hashMap.put("roleId", roleId); hashMap.put("permissionId", permissionId); List<GemPermissions> permissionButtonListByRoleIdAndPermissionId = permissionsMapper.findPermissionButtonByRoleIdAndPermissionId(hashMap); for (int i = 0 ; i < permissionButtonListByPermissionId.size() ; i++){ for (int j = 0 ; j < permissionButtonListByRoleIdAndPermissionId.size() ; j++){ if(permissionButtonListByPermissionId.get(i).getId().equals(permissionButtonListByRoleIdAndPermissionId.get(j).getId())){ permissionButtonListByPermissionId.get(i).setSelected(true); continue; } } } }else{ return null; } return permissionButtonListByPermissionId; }
Example 16
Source File: SysUserRoleServiceImpl.java From springboot-shiro with MIT License | 5 votes |
/** * 根据用户ID删除用户角色 * * @param userId */ @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public void removeByUserId(Long userId) { Example example = new Example(SysUserRole.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("userId", userId); resourceMapper.deleteByExample(example); }
Example 17
Source File: WechatUserInfoServiceImpl.java From wangsy-january with Apache License 2.0 | 5 votes |
@Override public List<WechatUserInfo> selectByConditions(WechatUserInfoValid valid) { Example example = new Example(WechatUserInfo.class); Example.Criteria criteria = example.createCriteria(); /** * 查询未被删除的数据 */ criteria.andEqualTo("beenDeleted", false); if(!StringUtils.isEmpty(valid.getOpenid())) { criteria.andEqualTo("openid", valid.getOpenid()); } return wechatUserInfoMapper.selectByCondition(example); }
Example 18
Source File: CommentServiceImpl.java From gpmall with Apache License 2.0 | 5 votes |
@Override public CommentResponse comment(CommentRequest request) { CommentResponse response = new CommentResponse(); try { request.requestCheck(); String orderItemId = request.getOrderItemId(); OrderItemRequest orderItemRequest = new OrderItemRequest(); orderItemRequest.setOrderItemId(orderItemId); OrderItemResponse orderItemResponse = orderQueryService.orderItem(orderItemRequest); String itemId = orderItemResponse.getItemId(); String orderId = orderItemResponse.getOrderId(); Example example = new Example(Comment.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("itemId", itemId); criteria.andEqualTo("orderId", orderId); criteria.andEqualTo("isDeleted", false); List<Comment> comments = commentMapper.selectByExample(example); if (CollectionUtils.isEmpty(comments)) { response.setCode(CommentRetCode.COMMENT_NOT_EXIST.getCode()); response.setMsg(CommentRetCode.COMMENT_NOT_EXIST.getMessage()); } else { response.setCode(CommentRetCode.SUCCESS.getCode()); response.setMsg(CommentRetCode.SUCCESS.getMessage()); response.setCommentDtoList(commentConverter.comment2Dto(comments)); } } catch (Exception e) { ExceptionProcessorUtil.handleException(response, e); } return response; }
Example 19
Source File: BaseService.java From springboot-seed with MIT License | 5 votes |
public Example createExample(QueryParameter... parameters) { Example example = new Example(getActualClass()); example.setOrderByClause("id desc"); Example.Criteria criteria = example.createCriteria(); for (QueryParameter parameter : parameters) { Object value = null; switch (parameter.getValueType()) { case STRING: value = parameter.getValue(); break; case LONG: value = Long.parseLong(parameter.getValue()); break; case ARRAY: value = parameter.getValue().split(","); break; } switch (parameter.getMethod()) { case LIKE: criteria.andLike(parameter.getType(), "%" + value + "%"); break; case EQUAL: criteria.andEqualTo(parameter.getType(), value); break; case IN: criteria.andIn(parameter.getType(), Arrays.asList((String[])value)); break; case IS_NULL: criteria.andIsNull(parameter.getType()); break; case IS_NOT_NULL: criteria.andIsNotNull(parameter.getType()); break; } } return example; }
Example 20
Source File: GoodsService.java From leyou with Apache License 2.0 | 5 votes |
/** * 分页查询SPU * * @param page * @param rows * @param key * @param saleable true-上架 false-下架 * @return */ public PageResult<SpuBo> querySpuByPageAndSort(Integer page, Integer rows, String key, Boolean saleable) { // 1、查询SPU // 开启分页,最多允许查询100条 PageHelper.startPage(page, Math.min(rows, 100)); // 过滤条件 Example example = new Example(Spu.class); Example.Criteria criteria = example.createCriteria(); // 上下架 if (saleable != null) { criteria.orEqualTo("saleable", saleable); } // 模糊查询 if (StringUtils.isNotBlank(key)) { criteria.andLike("title", "%" + key + "%"); } Page<Spu> pageInfo = (Page<Spu>) this.spuMapper.selectByExample(example); // 封装SPU视图类SpuBo List<SpuBo> list = pageInfo.getResult().stream().map(spu -> { // 2、将spu封装进spuBo SpuBo spuBo = new SpuBo(); // 属性拷贝 BeanUtils.copyProperties(spu, spuBo); // 3、查询spu的商品分类名称,要查三级分类 List<String> names = this.categoryService.queryNameByIds(Arrays.asList(spu.getCid1(), spu.getCid2(), spu.getCid3())); // 将分类名称拼接后接入 spuBo.setCname(StringUtils.join(names, "/")); // 4、查询spu的品牌名称 Brand brand = this.brandMapper.selectByPrimaryKey(spu.getBrandId()); spuBo.setBname(brand.getName()); return spuBo; }).collect(Collectors.toList()); return new PageResult<>(pageInfo.getTotal(), list); }