From 02b9636fecbc810bb4a58c42229a8ef1716812f9 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 21 Jan 2026 13:23:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(jpa):=20=E4=BF=AE=E5=A4=8D=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/jpa/TestApplication.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spring-boot-service-template-database/spring-boot-service-template-database-jpa/src/test/java/com/lanyuanxiaoyao/service/template/database/jpa/TestApplication.java b/spring-boot-service-template-database/spring-boot-service-template-database-jpa/src/test/java/com/lanyuanxiaoyao/service/template/database/jpa/TestApplication.java index 78c1530..818ec19 100644 --- a/spring-boot-service-template-database/spring-boot-service-template-database-jpa/src/test/java/com/lanyuanxiaoyao/service/template/database/jpa/TestApplication.java +++ b/spring-boot-service-template-database/spring-boot-service-template-database-jpa/src/test/java/com/lanyuanxiaoyao/service/template/database/jpa/TestApplication.java @@ -7,8 +7,9 @@ import com.lanyuanxiaoyao.service.template.database.jpa.entity.Company_; import com.lanyuanxiaoyao.service.template.database.jpa.entity.Employee; import com.lanyuanxiaoyao.service.template.database.jpa.entity.Employee_; import com.lanyuanxiaoyao.service.template.database.jpa.entity.QEmployee; +import com.lanyuanxiaoyao.service.template.database.jpa.repository.CompanyRepository; import com.lanyuanxiaoyao.service.template.database.jpa.repository.EmployeeRepository; -import java.sql.SQLException; +import com.lanyuanxiaoyao.service.template.database.jpa.repository.ReportRepository; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; @@ -24,11 +25,15 @@ import org.springframework.util.Assert; @EnableFenix @EnableJpaAuditing public class TestApplication extends AbstractTestApplication { + private final CompanyRepository companyRepository; private final EmployeeRepository employeeRepository; + private final ReportRepository reportRepository; - public TestApplication(JdbcTemplate jdbcTemplate, EmployeeRepository employeeRepository) { + public TestApplication(JdbcTemplate jdbcTemplate, CompanyRepository companyRepository, EmployeeRepository employeeRepository, ReportRepository reportRepository) { super(jdbcTemplate); + this.companyRepository = companyRepository; this.employeeRepository = employeeRepository; + this.reportRepository = reportRepository; } public static void main(String[] args) { @@ -36,7 +41,7 @@ public class TestApplication extends AbstractTestApplication { } @EventListener(ApplicationReadyEvent.class) - public void runTests() throws SQLException { + public void runTests() { testCrud(); testSpecification(); testNative(); @@ -45,7 +50,6 @@ public class TestApplication extends AbstractTestApplication { } private void testSpecification() { - // 增 var cid1 = saveItem("company", randomCompany()).get("data").asLong(); var cid2 = saveItem("company", randomCompany()).get("data").asLong(); var cid3 = saveItem("company", randomCompany()).get("data").asLong(); @@ -101,7 +105,9 @@ public class TestApplication extends AbstractTestApplication { ); Assert.isTrue(employees3.size() == 1, "查询数量错误"); - System.exit(0); + companyRepository.deleteAllById(List.of(cid1, cid2, cid3)); + employeeRepository.deleteAllById(List.of(eid1, eid2)); + reportRepository.deleteAllById(List.of(rid1, rid2)); } private void testNative() { @@ -117,5 +123,8 @@ public class TestApplication extends AbstractTestApplication { var list_native = employeeRepository.findAllEmployeeWithCompanyNameNative(); Assert.isTrue(list_native.size() == 3, "数量错误"); + + companyRepository.deleteAll(); + employeeRepository.deleteAll(); } }