Java Code Examples for tk.mybatis.mapper.entity.Example#setOrderByClause()
The following examples show how to use
tk.mybatis.mapper.entity.Example#setOrderByClause() .
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: LogServiceImpl.java From FEBS-Security with Apache License 2.0 | 6 votes |
@Override public List<SysLog> findAllLogs(SysLog log) { try { Example example = new Example(SysLog.class); Criteria criteria = example.createCriteria(); if (StringUtils.isNotBlank(log.getUsername())) { criteria.andCondition("username=", log.getUsername().toLowerCase()); } if (StringUtils.isNotBlank(log.getOperation())) { criteria.andCondition("operation like", "%" + log.getOperation() + "%"); } if (StringUtils.isNotBlank(log.getTimeField())) { String[] timeArr = log.getTimeField().split("~"); criteria.andCondition("date_format(CREATE_TIME,'%Y-%m-%d') >=", timeArr[0]); criteria.andCondition("date_format(CREATE_TIME,'%Y-%m-%d') <=", timeArr[1]); } example.setOrderByClause("create_time desc"); return this.selectByExample(example); } catch (Exception e) { logger.error("获取系统日志失败", e); return new ArrayList<>(); } }
Example 2
Source File: DictServiceImpl.java From FEBS-Security with Apache License 2.0 | 6 votes |
@Override public List<Dict> findAllDicts(Dict dict, QueryRequest request) { try { Example example = new Example(Dict.class); Criteria criteria = example.createCriteria(); if (StringUtils.isNotBlank(dict.getKeyy())) { criteria.andCondition("keyy=", Long.valueOf(dict.getKeyy())); } if (StringUtils.isNotBlank(dict.getValuee())) { criteria.andCondition("valuee=", dict.getValuee()); } if (StringUtils.isNotBlank(dict.getTableName())) { criteria.andCondition("table_name=", dict.getTableName()); } if (StringUtils.isNotBlank(dict.getFieldName())) { criteria.andCondition("field_name=", dict.getFieldName()); } example.setOrderByClause("dict_id"); return this.selectByExample(example); } catch (Exception e) { log.error("获取字典信息失败", e); return new ArrayList<>(); } }
Example 3
Source File: ContentServiceImpl.java From gpmall with Apache License 2.0 | 6 votes |
@Override public NavListResponse queryNavList() { NavListResponse response=new NavListResponse(); try { Example exampleContent = new Example(PanelContent.class); exampleContent.setOrderByClause("sort_order"); Example.Criteria criteriaContent = exampleContent.createCriteria(); criteriaContent.andEqualTo("panelId", GlobalConstants.HEADER_PANEL_ID); List<PanelContent> pannelContents = panelContentMapper.selectByExample(exampleContent); //添加缓存操作 TODO response.setPannelContentDtos(contentConverter.panelContents2Dto(pannelContents)); response.setCode(ShoppingRetCode.SUCCESS.getCode()); response.setMsg(ShoppingRetCode.SUCCESS.getMessage()); }catch (Exception e){ log.error("ContentServiceImpl.queryNavList Occur Exception :"+e); ExceptionProcessorUtils.wrapperHandlerException(response,e); } return response; }
Example 4
Source File: UserMapperTest.java From spring-boot-demo with MIT License | 6 votes |
/** * 测试通用Mapper - 条件查询 */ @Test public void testQueryByCondition() { initData(); Example example = new Example(User.class); // 过滤 example.createCriteria().andLike("name", "%Save1%").orEqualTo("phoneNumber", "17300000001"); // 排序 example.setOrderByClause("id desc"); int count = userMapper.selectCountByExample(example); // 分页 PageHelper.startPage(1, 3); // 查询 List<User> userList = userMapper.selectByExample(example); PageInfo<User> userPageInfo = new PageInfo<>(userList); Assert.assertEquals(3, userPageInfo.getSize()); Assert.assertEquals(count, userPageInfo.getTotal()); log.debug("【userPageInfo】= {}", userPageInfo); }
Example 5
Source File: GemDictionaryServiceImpl.java From gem with MIT License | 6 votes |
/** * @Description:查询字典列表 * @param name 名称 * @param code 编码 * @author: Ryan * @date 2018年11月13日 */ @Override public List<GemDictionary> findDictionMenu(String name, String code) { Example example = new Example(GemDictionary.class); Criteria createCriteria = example.createCriteria(); createCriteria.andEqualTo("parentId",-1); List<String> dicTypeList = new ArrayList<>(); dicTypeList.add("1"); dicTypeList.add("2"); createCriteria.andIn("dicType",dicTypeList); if(GemFrameStringUtlis.isNotBlank(name) && !name.equalsIgnoreCase("null") && name.length()>0) { createCriteria.andLike("name","%"+name+"%"); } if(GemFrameStringUtlis.isNotBlank(code) && !code.equalsIgnoreCase("null") && code.length()>0) { createCriteria.andLike("code","%"+code+"%"); } example.setOrderByClause("dic_sort asc"); List<GemDictionary> selectByExample = dictionaryMapper.selectByExample(example); return getDicChildrenList(selectByExample,name,code); }
Example 6
Source File: GemDictionaryServiceImpl.java From gem with MIT License | 6 votes |
/** * @Description:递归遍历所有的字典组 * @param list 字典数据集合 * @author: Ryan * @date 2018年11月5日 */ public List<GemDictionary> getDicChildrenList(List<GemDictionary> list,String name, String code) { if(list!=null && list.size()>0) { for (GemDictionary dictionary : list) { Example example = new Example(GemDictionary.class); Criteria createCriteria = example.createCriteria(); createCriteria.andEqualTo("parentId",dictionary.getId()); List<String> dicTypeList = new ArrayList<>(); dicTypeList.add("1"); dicTypeList.add("2"); createCriteria.andIn("dicType",dicTypeList); if(GemFrameStringUtlis.isNotBlank(name) && !name.equalsIgnoreCase("null") && name.length()>0) { createCriteria.andLike("name","%"+name+"%"); } if(GemFrameStringUtlis.isNotBlank(code) && !code.equalsIgnoreCase("null") && code.length()>0) { createCriteria.andLike("code","%"+code+"%"); } example.setOrderByClause("dic_sort asc"); List<GemDictionary> selectByExample = dictionaryMapper.selectByExample(example); dictionary.setChildren(selectByExample); getDicChildrenList(selectByExample,name,code); } } return list; }
Example 7
Source File: MenuServiceImpl.java From FEBS-Security with Apache License 2.0 | 6 votes |
@Override public List<Menu> findAllMenus(Menu menu) { try { Example example = new Example(Menu.class); Criteria criteria = example.createCriteria(); if (StringUtils.isNotBlank(menu.getMenuName())) { criteria.andCondition("menu_name=", menu.getMenuName()); } if (StringUtils.isNotBlank(menu.getType())) { criteria.andCondition("type=", Long.valueOf(menu.getType())); } example.setOrderByClause("menu_id"); return this.selectByExample(example); } catch (NumberFormatException e) { log.error("error", e); return new ArrayList<>(); } }
Example 8
Source File: BrandService.java From leyou with Apache License 2.0 | 6 votes |
/** * 条件查询品牌-含分页 * * @param page 当前页 * @param rows 每页大小 * @param sortBy 排序字段 * @param desc 是否为降序 * @param key 搜索关键字 * @return */ public PageResult<Brand> queryBrandByPageAndSort(Integer page, Integer rows, String sortBy, Boolean desc, String key) { // 开启分页 PageHelper.startPage(page, rows); // 过滤 Example example = new Example(Brand.class); // if (StringUtils.isNotBlank(key)) { if (key != null && !"".equals(key)) { // 条件非空,name-品牌名称 letter-品牌首字母 example.createCriteria().andLike("name", "%" + key + "%").orEqualTo("letter", key); } if (sortBy != null && !"".equals(sortBy)) { // 排序 order by 属性名 DESC/ASC String orderByClause = sortBy + (desc ? " DESC " : " ASC "); example.setOrderByClause(orderByClause); } // 查询 Page<Brand> pageInfo = (Page<Brand>) brandMapper.selectByExample(example); // 返回结果 return new PageResult<>(pageInfo.getTotal(), pageInfo); }
Example 9
Source File: UserMapperTest.java From spring-boot-demo with MIT License | 6 votes |
/** * 测试通用Mapper - 条件查询 */ @Test public void testQueryByCondition() { initData(); Example example = new Example(User.class); // 过滤 example.createCriteria().andLike("name", "%Save1%").orEqualTo("phoneNumber", "17300000001"); // 排序 example.setOrderByClause("id desc"); int count = userMapper.selectCountByExample(example); // 分页 PageHelper.startPage(1, 3); // 查询 List<User> userList = userMapper.selectByExample(example); PageInfo<User> userPageInfo = new PageInfo<>(userList); Assert.assertEquals(3, userPageInfo.getSize()); Assert.assertEquals(count, userPageInfo.getTotal()); log.debug("【userPageInfo】= {}", userPageInfo); }
Example 10
Source File: GemPermissionsServiceImpl.java From gem with MIT License | 5 votes |
/** * @Description: 获取权限数据 * @param menusType 菜单0为菜单1按钮 * @author: Ryan * @date 2018年11月5日 */ private List<GemPermissions> findPermissionMenu(Integer menusType) { Example example = new Example(GemPermissions.class); Example.Criteria createCriteria = example.createCriteria(); createCriteria.andEqualTo("menusType",menusType); example.setOrderByClause("per_sort asc"); List<GemPermissions> selectByExample = permissionsMapper.selectByExample(example); return selectByExample; }
Example 11
Source File: RoleServiceImpl.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Override public List<Role> findAllRole(Role role) { try { Example example = new Example(Role.class); if (StringUtils.isNotBlank(role.getRoleName())) { example.createCriteria().andCondition("role_name=", role.getRoleName()); } example.setOrderByClause("create_time"); return this.selectByExample(example); } catch (Exception e) { log.error("获取角色信息失败", e); return new ArrayList<>(); } }
Example 12
Source File: MenuServiceImpl.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Override public Tree<Menu> getMenuTree() { List<Tree<Menu>> trees = new ArrayList<>(); Example example = new Example(Menu.class); example.createCriteria().andCondition("type =", 0); example.setOrderByClause("create_time"); List<Menu> menus = this.selectByExample(example); buildTrees(trees, menus); return TreeUtils.build(trees); }
Example 13
Source File: DeptServiceImpl.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Override public List<Dept> findAllDepts(Dept dept) { try { Example example = new Example(Dept.class); if (StringUtils.isNotBlank(dept.getDeptName())) { example.createCriteria().andCondition("dept_name=", dept.getDeptName()); } example.setOrderByClause("dept_id"); return this.selectByExample(example); } catch (Exception e) { log.error("获取部门列表失败", e); return new ArrayList<>(); } }
Example 14
Source File: BaseService.java From springboot-seed with MIT License | 5 votes |
/** * 根据页数获取实例列表 * * @param page 页数 * @return 实例列表 */ public List<T> selectAll(int page) { Example example = new Example(getActualClass()); example.setOrderByClause("id desc"); PageHelper.startPage(page, Constant.PAGE_SIZE); return mapper.selectByExample(example); }
Example 15
Source File: ExtendService.java From springboot-seed with MIT License | 5 votes |
/** * 根据用户ID获取用户关联信息列表(限制用户关联表使用) * * @param userId 用户ID * @return 实例列表 */ public List<T> selectAllByUserId(Long userId) { Example example = new Example(getActualClass()); example.setOrderByClause("id desc"); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("userId", userId); return mapper.selectByExample(example); }
Example 16
Source File: GemPermissionsServiceImpl.java From gem with MIT License | 5 votes |
/** * @Description: 查看菜单下的按钮 * @param parentId 菜单主键 * @author: Ryan * @date 2018年11月5日 */ @Override public List<GemPermissions> findPermissionButtonByParentId(Long parentId) { Example example = new Example(GemPermissions.class); Example.Criteria createCriteria = example.createCriteria(); createCriteria.andEqualTo("parentId",parentId); createCriteria.andEqualTo("menusType",1); example.setOrderByClause("per_sort asc"); List<GemPermissions> selectByExample = permissionsMapper.selectByExample(example); return selectByExample; }
Example 17
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 18
Source File: BaseService.java From springboot-seed with MIT License | 5 votes |
/** * 根据字段(ID列表)和页数获取实例列表 * * @param type 字段 * @param ids ID列表 * @param page 页数 * @return 实例列表 */ public List<T> selectAll(String type, List<Long> ids, int page) { 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); PageHelper.startPage(page, Constant.PAGE_SIZE); return mapper.selectByExample(example); } }
Example 19
Source File: HomeServiceImpl.java From gpmall with Apache License 2.0 | 5 votes |
@Override public HomePageResponse homepage() { log.info("Begin HomeServiceImpl.homepage"); HomePageResponse response=new HomePageResponse(); response.setCode(ShoppingRetCode.SUCCESS.getCode()); response.setMsg(ShoppingRetCode.SUCCESS.getMessage()); try { String json= cacheManager.checkCache(GlobalConstants.HOMEPAGE_CACHE_KEY); if(StringUtils.isNoneEmpty(json)){ List<PanelDto> panelDtoList=JSON.parseArray(json,PanelDto.class); Set set=new HashSet(panelDtoList); response.setPanelContentItemDtos(set); return response; } Example panelExample = new Example(Panel.class); Example.Criteria criteria = panelExample.createCriteria(); criteria.andEqualTo("position", 0); criteria.andEqualTo("status", 1); panelExample.setOrderByClause("sort_order"); List<Panel> panels = panelMapper.selectByExample(panelExample); Set<PanelDto> panelContentItemDtos = new HashSet<PanelDto>(); panels.parallelStream().forEach(panel -> { List<PanelContentItem> panelContentItems = panelContentMapper.selectPanelContentAndProductWithPanelId(panel.getId()); PanelDto panelDto = contentConverter.panen2Dto(panel); panelDto.setPanelContentItems(contentConverter.panelContentItem2Dto(panelContentItems)); panelContentItemDtos.add(panelDto); }); cacheManager.setCache(GlobalConstants.HOMEPAGE_CACHE_KEY,JSON.toJSONString(panelContentItemDtos),GlobalConstants.HOMEPAGE_EXPIRE_TIME); response.setPanelContentItemDtos(panelContentItemDtos); }catch (Exception e){ log.error("HomeServiceImpl.homepage Occur Exception :"+e); ExceptionProcessorUtils.wrapperHandlerException(response,e); } return response; }
Example 20
Source File: YsServiceImpl.java From dbys with GNU General Public License v3.0 | 4 votes |
@Override public List<Ysb> getNewYsb(int num) { Example example = new Example(Ysb.class); example.setOrderByClause("gxtime DESC limit 0,"+num); return ysbMapper.selectByExample(example); }