mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
重构 apt 功能,其配置从 mybatis-flex.properties 移动到根目录的 apt.config; close #I7FHYB
This commit is contained in:
parent
e47500779f
commit
50fd0fff80
@ -9,7 +9,7 @@ MyBatis-Flex 使用了 APT(Annotation Processing Tool)技术,在项目编
|
|||||||
|
|
||||||
## 配置文件和选项
|
## 配置文件和选项
|
||||||
|
|
||||||
要对MyBatis-Flex 的APT细节选项进行配置,你需要在`resources`目录下创建名为`mybatis-flex.properties`的文件。
|
要对 MyBatis-Flex 的 APT 细节选项进行配置,你需要在项目的 **根目录** 下创建名为 `apt.config` 的文件。
|
||||||
|
|
||||||
支持的配置选项如下:
|
支持的配置选项如下:
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class MybatisFlexConfig {
|
|||||||
/**
|
/**
|
||||||
* 配置文件名。
|
* 配置文件名。
|
||||||
*/
|
*/
|
||||||
private static final String MYBATIS_FLEX = "mybatis-flex.properties";
|
private static final String APT_FILE_NAME = "apt.config";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mybatis-flex.properties
|
* mybatis-flex.properties
|
||||||
@ -50,32 +50,18 @@ public class MybatisFlexConfig {
|
|||||||
public MybatisFlexConfig(Filer filer) {
|
public MybatisFlexConfig(Filer filer) {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
FileObject propertiesFileObject = filer.getResource(StandardLocation.CLASS_OUTPUT, "", MYBATIS_FLEX);
|
//target/classes/apt.config
|
||||||
|
FileObject aptConfigFileObject = filer.getResource(StandardLocation.CLASS_OUTPUT, "", APT_FILE_NAME);
|
||||||
|
String projectRootPath = FileUtil.getProjectRootPath(aptConfigFileObject.toUri().getPath());
|
||||||
|
|
||||||
File propertiesFile = new File(propertiesFileObject.toUri());
|
|
||||||
|
|
||||||
if (propertiesFile.exists()) {
|
File aptConfigFile = new File(aptConfigFileObject.toUri());
|
||||||
inputStream = propertiesFileObject.openInputStream();
|
while (!aptConfigFile.exists() && !projectRootPath.equals(aptConfigFile.getParentFile().getAbsolutePath())) {
|
||||||
} else if (getClass().getClassLoader().getResource(MYBATIS_FLEX) != null) {
|
aptConfigFile = new File(aptConfigFile.getParentFile().getParentFile(), APT_FILE_NAME);
|
||||||
inputStream = getClass().getClassLoader().getResourceAsStream(MYBATIS_FLEX);
|
|
||||||
} else {
|
|
||||||
File pomXmlFile = new File(propertiesFile.getParentFile().getParentFile().getParentFile(), "pom.xml");
|
|
||||||
if (pomXmlFile.exists()) {
|
|
||||||
propertiesFile = new File(pomXmlFile.getParentFile(), "src/main/resources/mybatis-flex.properties");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputStream == null && propertiesFile.exists()) {
|
if (aptConfigFile.exists()) {
|
||||||
inputStream = Files.newInputStream(propertiesFile.toPath());
|
inputStream = Files.newInputStream(aptConfigFile.toPath());
|
||||||
}
|
|
||||||
|
|
||||||
// 兜底,如果还是没找到,就找项目根目录下的 mybatis-flex.properties
|
|
||||||
if (inputStream == null) {
|
|
||||||
final String projectRootPath = FileUtil.getProjectRootPath(propertiesFileObject.toUri().getPath());
|
|
||||||
final File filePath = new File(projectRootPath, MYBATIS_FLEX);
|
|
||||||
if (filePath.exists()) {
|
|
||||||
inputStream = Files.newInputStream(filePath.toPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
|
|||||||
2
mybatis-flex-test/mybatis-flex-spring-test/apt.config
Normal file
2
mybatis-flex-test/mybatis-flex-spring-test/apt.config
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
processor.mappersGenerateEnable = false
|
||||||
|
processor.allInTables = true
|
||||||
@ -30,7 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.mybatisflex.test.model.table.Tables.account_def;
|
import static com.mybatisflex.test.model.table.Tables.ACCOUNT;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = AppConfig.class)
|
@ContextConfiguration(classes = AppConfig.class)
|
||||||
@ -49,7 +49,7 @@ public class AccountTest implements WithAssertions {
|
|||||||
@Test
|
@Test
|
||||||
public void testSelectByQuery() {
|
public void testSelectByQuery() {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(account_def.age.eq(18));
|
.where(ACCOUNT.AGE.eq(18));
|
||||||
List<Account> accounts = accountMapper.selectListByQuery(queryWrapper);
|
List<Account> accounts = accountMapper.selectListByQuery(queryWrapper);
|
||||||
assertThat(accounts.size()).isEqualTo(1);
|
assertThat(accounts.size()).isEqualTo(1);
|
||||||
assertThat(accounts.get(0).getAge()).isEqualTo(18);
|
assertThat(accounts.get(0).getAge()).isEqualTo(18);
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
processor.mappersGenerateEnable = true
|
|
||||||
Loading…
x
Reference in New Issue
Block a user