-
Notifications
You must be signed in to change notification settings - Fork 169
Open
Description
参考:https://vladmihalcea.com/spring-jpa-dto-projection/
实际案例如下:
- 新建WorkflowThroughputPhaseCountDto 内容如下
@Data
public class WorkflowThroughputPhaseCountDto {
// 注意构造方法会被JPQL使用
public WorkflowThroughputPhaseCountDto(Long WorkflowThroughputPhaseId, ActionStatus actionStatus, Long workflowThroughputPhaseCount) {
this.workflowTemplatePhaseId = WorkflowThroughputPhaseId;
this.workflowThroughputPhaseCount = workflowThroughputPhaseCount;
this.actionStatus = actionStatus;
}
private Long workflowTemplatePhaseId;
private Long workflowThroughputPhaseCount;
private ActionStatus actionStatus;
}
- Repository里面的写法如下,注意要用到 new Dto全路径类前面的构造方法
@Repository
public interface WorkflowThroughputPhaseRepository extends JpaRepository<WorkflowThroughputPhase, Long> {
@Query(value = "select new com.mega.workflow.suite.service.dto.WorkflowThroughputPhaseCountDto(wt.workflowTemplatePhaseId,wt.status,count(wt.id)) " +
"from WorkflowThroughputPhase wt where wt.workflowId = :workflowId group by wt.status,wt.workflowTemplatePhaseId")
List<WorkflowThroughputPhaseCountDto> findCountByWorkflowId(@Param("workflowId") Long workflowId);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels