Spring—data-jpa条件分页和删除注意事项

分页查询
//第几页
int page = 1;
//每页显示几个
int size = 2;
Pageable pageable = new PageRequest(page, size, null);//封装分页查询条件
List a= calculateIndexValueRepository.findByCalculateIndex(indexid, pageable);

@Query("select a from CalculateIndexValue a where a.calculateIndex=?1 group by a.pubdate order by a.pubdate ")
ListfindByCalculateIndex(String calculateIndex, Pageable pageable);

自定义查询返回值类型
@Query(value = “select new map(c.id,c.name,c.describe,c.updateDate,c.quoteIndexId,c.unit,m.formula,c.type,c.freq,c.alias) from CalculateIndex c, IndexFormula m where c.type= ?1 and c.mechanismId = ?2 and c.id = m.calculateIndexId order by c.updateDate desc”)
List getAllFactorIndex(String type, String mechanismId);

@Query(value = “select new map(c.id,c.name,c.describe,c.updateDate,c.quoteIndexId,c.unit,m.formula,c.type,c.freq,c.alias) from CalculateIndex c, IndexFormula m where ((c.type in(‘base’,‘calculate’) and c.mechanismId is null) or " +” (c.type in(‘since’,‘factor’) and c.mechanismId = ?1)) and c.id = m.calculateIndexId")
List getAllFactorAndIndexByMechanismId(String mechanismId);

@Query(value = “select new map(c.id,c.name,c.describe,c.updateDate,c.quoteIndexId,c.unit,m.formula,c.type,c.freq,c.alias) from CalculateIndex c, IndexFormula m where ((c.type in(‘base’,‘calculate’) and c.mechanismId is null) or " + " (c.type in(‘since’,‘factor’) and c.mechanismId = ?1)) and c.id = m.calculateIndexId and c.id <> ?2”)
List getAllFactorAndIndexByMechanismIdAndNotId(String mechanismId, String id);

@Query(value = "select c.id from CalculateIndex c where c.type=‘base’ and c.freq=?1 and c.mechanismId is null ")
List getAllBaseIds(String freq);

自定义多条件删除
@Modifying //这里是关键
@Transactional //这里是关键
@Query(“delete from CalculateIndexValue a where a.calculateIndex=?1 and a.mechanismId=?2 and a.pubdate=?3”)
void deleteallwhere(String CalculateIndex, String mechanismId, Date pubdate);

你可能感兴趣的:(spring-data-jpa,Java代码)