/** * 按照属性查找对象,匹配方式为"in" * * @param propertyName 属性名称 * @param value 属性值 * @param orderByProperty 排序属性名称 * @param isDesc true:降序,false:升序 * @return */ @SuppressWarnings("unchecked") public List<T> findByPropertyAndOrderWithParams( final Class<T> entityClass, final String propertyName, final Collection<?> values, final String orderByProperty, boolean isDesc) { Assert.hasText(propertyName, "propertyName不能为空"); Search search = new Search(entityClass); SearchUtil.addFilterIn(search, propertyName, values); SearchUtil.addSort(search, orderByProperty, isDesc); return searchProcessor.search(this.getEntityManager().getPersistEntityManager(), search); }
/** * 根据id获取对象列表,并排序 * * @param ids * @param orderByProperty * @param isDesc true 降序,false升序 * @return */ @SuppressWarnings("unchecked") public List<T> get( final Class<T> entityClass, final Collection<PK> ids, String orderByProperty, boolean isDesc) { Search search = new Search(entityClass); search.setResultMode(Search.RESULT_LIST); JPAAnnotationMetadataUtil metadataUtil = new JPAAnnotationMetadataUtil(); T entity; try { entity = entityClass.newInstance(); } catch (Exception e) { logger.error("根据主键集合查找对象 {}发生异常! ", entityClass.getClass()); throw new RuntimeException("根据主键集合查找对象发生异常", e); } String propertyName = metadataUtil.getIdPropertyName(entity); SearchUtil.addFilterIn(search, propertyName, ids); SearchUtil.addSort(search, orderByProperty, isDesc); return searchProcessor.search(this.getEntityManager().getPersistEntityManager(), search); }
/** * 获取全部对象, 支持按属性行序 * * @param orderByProperty 排序的属性名称 * @param isDesc true:降序,false:升序 * @return */ @SuppressWarnings("unchecked") public List<T> getAll(final Class<T> entityClass, String orderByProperty, boolean isDesc) { Search search = new Search(entityClass); SearchUtil.addSort(search, orderByProperty, isDesc); return searchProcessor.search(this.getEntityManager().getPersistEntityManager(), search); }
/** * Add sort by property. Ascending if <code>desc == false</code>, descending if <code>desc == true * </code>. */ public Search addSort(String property, boolean desc, boolean ignoreCase) { SearchUtil.addSort(this, property, desc, ignoreCase); return this; }
/** * Add sort by property. Ascending if <code>desc == false</code>, descending if <code>desc == true * </code>. */ public Search addSort(String property, boolean desc) { SearchUtil.addSort(this, property, desc); return this; }
// Sorts public Search addSort(Sort sort) { SearchUtil.addSort(this, sort); return this; }