更改为构造注入并完善方法注释

This commit is contained in:
thinkgem
2025-10-12 20:34:18 +08:00
parent 67b3649c15
commit 5426668cdb
30 changed files with 202 additions and 167 deletions

View File

@@ -4,18 +4,16 @@
*/
package com.jeesite.modules.test.db;
import com.jeesite.common.datasource.DataSourceHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import com.jeesite.common.config.Global;
import com.jeesite.common.datasource.DataSourceHolder;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.tests.BaseInitDataTests;
import com.jeesite.modules.gen.entity.GenTable;
import com.jeesite.modules.gen.entity.GenTableColumn;
import com.jeesite.modules.gen.service.GenTableService;
import com.jeesite.modules.gen.utils.GenUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
/**
* 初始化核心表数据
@@ -26,6 +24,10 @@ import com.jeesite.modules.gen.utils.GenUtils;
@ConditionalOnProperty(name="jeesite.initdata", havingValue="true", matchIfMissing=false)
public class InitTestData extends BaseInitDataTests {
public InitTestData(GenTableService genTableService) {
this.genTableService = genTableService;
}
@Override
public boolean initData() throws Exception {
if (GenUtils.isTableExists("test_data")) {
@@ -36,8 +38,7 @@ public class InitTestData extends BaseInitDataTests {
return true;
}
@Autowired
private GenTableService genTableService;
private final GenTableService genTableService;
/**
* 代码生成测试数据
*/

View File

@@ -14,7 +14,6 @@ import com.jeesite.modules.test.dao.TestDataChildDao;
import com.jeesite.modules.test.dao.TestDataDao;
import com.jeesite.modules.test.entity.TestData;
import com.jeesite.modules.test.entity.TestDataChild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -28,9 +27,12 @@ import java.util.List;
@Service
public class TestDataService extends CrudService<TestDataDao, TestData> {
@Autowired
private TestDataChildDao testDataChildDao;
private final TestDataChildDao testDataChildDao;
public TestDataService(TestDataChildDao testDataChildDao) {
this.testDataChildDao = testDataChildDao;
}
/**
* 获取单条数据
* @param testData 主键

View File

@@ -9,7 +9,6 @@ import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.test.dao.TestDataDao;
import com.jeesite.modules.test.entity.TestData;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@@ -24,9 +23,12 @@ import java.util.List;
@SpringBootTest(classes = ApplicationTest.class)
public class InsertBatchTest extends BaseSpringContextTests {
@Autowired
private TestDataDao testDataDao;
private final TestDataDao testDataDao;
public InsertBatchTest(TestDataDao testDataDao) {
this.testDataDao = testDataDao;
}
@Test
public void testData1() throws Exception{
List<TestData> list = ListUtils.newArrayList();

View File

@@ -11,7 +11,6 @@ import com.jeesite.modules.test.entity.TestData;
import com.jeesite.modules.test.entity.TestDataChild;
import com.jeesite.modules.test.service.TestDataService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@@ -32,9 +31,12 @@ import java.util.concurrent.Executors;
@SpringBootTest(classes = ApplicationTest.class)
public class MultiDataSourceTest extends BaseSpringContextTests {
@Autowired
private TestDataService testDataService;
private final TestDataService testDataService;
public MultiDataSourceTest(TestDataService testDataService) {
this.testDataService = testDataService;
}
@Test
public void testData() throws Exception{
ExecutorService pool = Executors.newCachedThreadPool();