From e3c88fb8ee9549de7c23afcde0c92957a693e68e Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Fri, 19 Sep 2025 17:53:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=9B=B8=E5=90=8C=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/template/entity/vo/EmployeeWithCompanyName.java | 4 +--- .../service/template/repository/EmployeeRepository.java | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/lanyuanxiaoyao/service/template/entity/vo/EmployeeWithCompanyName.java b/src/test/java/com/lanyuanxiaoyao/service/template/entity/vo/EmployeeWithCompanyName.java index cae70d1..7ffa2b6 100644 --- a/src/test/java/com/lanyuanxiaoyao/service/template/entity/vo/EmployeeWithCompanyName.java +++ b/src/test/java/com/lanyuanxiaoyao/service/template/entity/vo/EmployeeWithCompanyName.java @@ -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 ) { } diff --git a/src/test/java/com/lanyuanxiaoyao/service/template/repository/EmployeeRepository.java b/src/test/java/com/lanyuanxiaoyao/service/template/repository/EmployeeRepository.java index 59be417..cbc22da 100644 --- a/src/test/java/com/lanyuanxiaoyao/service/template/repository/EmployeeRepository.java +++ b/src/test/java/com/lanyuanxiaoyao/service/template/repository/EmployeeRepository.java @@ -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 { Optional findOne(Specification 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> findAllEmployeeWithCompanyNameNative(); + List 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 findAllEmployeeWithCompanyName(); }