【发布时间】:2021-03-20 03:06:53
【问题描述】:
我正在尝试使用此代码构建参数化顺序并按本机查询排序:
@Query(value = "SELECT e.first_name as firstName, e.last_name as lastName, jh.start_date as startDate, jh.end_date as endDate, " +
"j.job_title as jobName, d.department_name as departmentName FROM JOB_HISTORY jh " +
"JOIN JOBS j ON jh.JOB_ID = j.JOB_ID " +
"JOIN DEPARTMENTS d ON JH.DEPARTMENT_ID = d.DEPARTMENT_ID " +
"JOIN EMPLOYEES e ON jh.EMPLOYEE_ID = e.EMPLOYEE_ID " +
"ORDER BY :sortBy :orderBy", nativeQuery = true)
List<EmployeeJobView> getAllEmployeeJob(String sortBy, String orderBy);
这给了我一个例外,并且不是按 HQL 进行订购的正确方法。
这里是投影界面
public interface EmployeeJobView {
@Value("#{target.firstName + ' ' + target.lastName}")
String getFullName();
Timestamp getStartDate();
Timestamp getEndDate();
String getJobName();
String getDepartmentName();
}
正确的做法是什么?
【问题讨论】: