1
0

fix: 增加返回值相同的示例

This commit is contained in:
2025-09-19 17:53:56 +08:00
parent 2615fc02fd
commit e3c88fb8ee
2 changed files with 3 additions and 6 deletions

View File

@@ -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
) {
}

View File

@@ -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();
}