@Query("select p from WhpzxryzsXxPo p where p.ryxm like concat('%',?1,'%') and p.cyyxqq >= ?2")
4.查询结果为VO
含两个实体类
@Query(value = "SELECT new com.kun.aqsczt.vo.FxjzfbVo(u, seventinfo) FROM SSmsInfo u left join SEventInfo seventinfo on u.referId = seventinfo.eventId WHERE (:referType IS NULL OR :referType IS '' OR u.referType = :referType) AND (:isSend IS NULL OR :isSend IS '' OR u.isSend = :isSend) ")
5.使用@Param注解注入参数
分页查询
@Query(value = "SELECT a FROM CEiWorkaccMaybe a " +
"WHERE (:psnName IS NULL OR :psnName IS '' OR a.psnName LIKE %:psnName%) " +
"AND (:commName IS NULL OR :commName IS '' OR a.commName LIKE %:commName%) " +
"AND (:idCard IS NULL OR :idCard IS '' OR a.idCard LIKE %:idCard%) " +
"AND (:doctorDateStart IS NULL OR :doctorDateStart IS '' OR a.doctorDate >= :doctorDateStart) " +
"AND (:doctorDateEnd IS NULL OR :doctorDateEnd IS '' OR a.doctorDate <= :doctorDateEnd) "
)
Page<CEiWorkaccMaybe> getSuspectedWorkAccidentVerification(
@Param("psnName") String psnName,
@Param("commName") String commName,
@Param("idCard") String idCard,
@Param("doctorDateStart") String doctorDateStart,
@Param("doctorDateEnd") String doctorDateEnd,
Pageable pageable
);
@Query(value = "select m.field AS field,COUNT(m.field) AS size from MigrationObject m where m.xmlName = ?1 and m.groupName = ?2 group by m.field")
List<WorkCenter> getKey(String xmlName, String groupName);
对于这种情况,只返回了两个字段,就需要定义一个接口来接收(注意AS别名的配置)
public interface WorkCenter {
String getField();
String getSize();
}
最后跑一下demo代码
List<WorkCenter> list = migrationObjectRepository.getKey("EN_Work centerResource.xml","Key");
for (WorkCenter workCenter:list){
System.out.println(workCenter.getField());
System.out.println(workCenter.getSize());
}