fix: 增加返回值相同的示例
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package com.lanyuanxiaoyao.service.template.entity.vo;
|
||||
|
||||
import com.lanyuanxiaoyao.service.template.entity.Employee;
|
||||
|
||||
public record EmployeeWithCompanyName(
|
||||
String name,
|
||||
String companyName,
|
||||
Integer age,
|
||||
Employee.Role role
|
||||
String role
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.lanyuanxiaoyao.service.template.repository;
|
||||
import com.lanyuanxiaoyao.service.template.entity.Employee;
|
||||
import com.lanyuanxiaoyao.service.template.entity.vo.EmployeeWithCompanyName;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
@@ -18,8 +17,8 @@ public interface EmployeeRepository extends SimpleRepository<Employee> {
|
||||
Optional<Employee> findOne(Specification<Employee> specification);
|
||||
|
||||
@Query(value = "select e.name, c.name, e.age, e.role from employee e, company c where e.company_id = c.id", nativeQuery = true)
|
||||
List<Map<String, Object>> findAllEmployeeWithCompanyNameNative();
|
||||
List<EmployeeWithCompanyName> findAllEmployeeWithCompanyNameNative();
|
||||
|
||||
@Query("select new com.lanyuanxiaoyao.service.template.entity.vo.EmployeeWithCompanyName(employee.name, employee.company.name, employee.age, employee.role) from Employee employee")
|
||||
@Query("select new com.lanyuanxiaoyao.service.template.entity.vo.EmployeeWithCompanyName(employee.name, employee.company.name, employee.age, cast(employee.role as string)) from Employee employee")
|
||||
List<EmployeeWithCompanyName> findAllEmployeeWithCompanyName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user