项目中使用JPA CRUD
对于select 查询语句,基本用法如下:(这里直接引用别人博客,主要是因为多包含了一个Subquery。自己目前所在项目中的这种查询代码,基本一样,直接参考即可)
另外,需要补充的是,近期需要在查询中附加某字段的升降序(order by 字段 desc)
添加的代码如下:
criteriaQuery.where(restrictions);
criteriaQuery.orderBy(criteriaBuilder.desc(root.<Date>get("createdDate"))); //重点
多字段排序(如下)
criteriaQuery.orderBy(criteriaBuilder.desc(root.<Date>get("createdDate")),criteriaBuilder.desc( xx ));