-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# 字段类型别名支持 | ||
|
||
可以参考当前项目的 `idoc-test` 模块。 | ||
|
||
## 为什么需要 | ||
|
||
有时候页面显示类型,希望更加友好。 | ||
|
||
所以系统内置了一些别名显示,也同时支持自定义别名。 | ||
|
||
# 类型字段的别名 | ||
|
||
## 系统内置 | ||
|
||
系统当前版本提供了常见的别名。 | ||
|
||
详情见 `com.github.houbb.idoc.core.util.JavaTypeAliasUtil` | ||
|
||
| 类型 | 别称 | | ||
|:---|:---| | ||
| java.lang.Float | 浮点型 | | ||
| java.lang.Double | 浮点型 | | ||
| java.util.Date | 日期 | | ||
| java.time.LocalDateTime | 日期时间 | | ||
| java.util.Currency | 货币 | | ||
| float | 浮点型 | | ||
| java.lang.Integer | 整型 | | ||
| long | 长整型 | | ||
| java.math.BigDecimal | 数字 | | ||
| java.lang.Character | 字符 | | ||
| java.lang.Long | 长整型 | | ||
| java.lang.Short | 短整型 | | ||
| java.util.Map | 映射 | | ||
| java.time.LocalTime | 时间 | | ||
| java.lang.Boolean | 布尔值 | | ||
| java.math.BigInteger | 数字 | | ||
| java.lang.String | 字符串 | | ||
| java.lang.Byte | 字节 | | ||
| double | 浮点型 | | ||
| byte | 字节 | | ||
| java.util.Collection | 集合 | | ||
| int | 整型 | | ||
| java.util.List | 列表 | | ||
| boolean | 布尔值 | | ||
| java.time.LocalDate | 日期 | | ||
| char | 字符 | | ||
| short | 短整型 | | ||
|
||
## 自定义的方式 | ||
|
||
可以通过 typeAlias 指定自定义的字段别称。 | ||
|
||
```xml | ||
<configuration> | ||
<generateFilters> | ||
<generateFilter>com.github.houbb.idoc.test.filter.MyGenerateFilter</generateFilter> | ||
</generateFilters> | ||
<isAllInOne>true</isAllInOne> | ||
<typeAliases> | ||
<typeAlias> | ||
<key>java.lang.String</key> | ||
<value>String自定义说明</value> | ||
</typeAlias> | ||
</typeAliases> | ||
</configuration> | ||
``` | ||
|
||
## 优先级 | ||
|
||
用户自定义的字段别名优先级高于系统默认。 | ||
|
||
后面定义的别名会直接覆盖前面的别名。 | ||
|
||
# 测试代码演示 | ||
|
||
## 对象定义 | ||
|
||
```java | ||
/** | ||
* 别名测试 | ||
* @author binbin.hou | ||
* @since 0.0.1 | ||
*/ | ||
public class TypeAliasSimpleBean { | ||
|
||
/** | ||
* 名称 | ||
*/ | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
``` | ||
|
||
## 测试日志 | ||
|
||
运行测试日志如下: | ||
|
||
``` | ||
{"comment":"别名测试","docAnnotationList":[],"docFieldList":[{"comment":"名称","name":"name","type":"java.lang.String","typeAlias":"String自定义说明"}],"docMethodList":[{"docMethodParameterList":[],"docMethodReturn":{"fullName":"java.lang.String","name":"String","packageName":"java.lang"},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"getName","seeList":[],"signature":"getName()"},{"docMethodParameterList":[{"docAnnotationList":[],"name":"name","type":"java.lang.String","typeAlias":"String自定义说明"}],"docMethodReturn":{},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"setName","seeList":[],"signature":"setName(name)"}],"docTagList":[{"lineNum":5,"name":"author","parameters":["binbin.hou"],"value":"binbin.hou"},{"lineNum":6,"name":"since","parameters":["0.0.1"],"value":"0.0.1"}],"fullName":"com.github.houbb.idoc.test.model.TypeAliasSimpleBean","modifiers":["public"],"name":"TypeAliasSimpleBean","packageName":"com.github.houbb.idoc.test.model"} | ||
``` | ||
|
||
其中 typeAlias 就是字段类型的别名,我们可以用来更加友好的显示字段信息。 | ||
|
||
# 其他的思考 | ||
|
||
## 自定义方式的便利性 | ||
|
||
自定义的方式采用基于 xml 的方式是比较方便。 | ||
|
||
但是数量比较多的时候就没有那么方便,本来考虑添加对应的配置属性接口,权衡下还是使用了 xml 配置的方式。 | ||
|
||
## i18n | ||
|
||
到目前为止,本项目的设计都过于拘泥于中文。 | ||
|
||
后期如果考虑到扩展的话,将考虑添加 i18n 支持。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
idoc-test/src/main/java/com/github/houbb/idoc/test/filter/MyGenerateAliasFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.houbb.idoc.test.filter; | ||
|
||
import com.github.houbb.idoc.api.core.filter.IDocGenerateFilter; | ||
import com.github.houbb.idoc.api.model.metadata.DocClass; | ||
|
||
/** | ||
* 自定义生成过滤器 | ||
* @author binbin.hou | ||
* @since 0.1.0 | ||
*/ | ||
public class MyGenerateAliasFilter implements IDocGenerateFilter { | ||
|
||
@Override | ||
public boolean include(DocClass docClass) { | ||
if("TypeAliasSimpleBean".equalsIgnoreCase(docClass.getName())) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
idoc-test/src/main/java/com/github/houbb/idoc/test/model/TypeAliasSimpleBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.houbb.idoc.test.model; | ||
|
||
/** | ||
* 别名测试 | ||
* @author binbin.hou | ||
* @since 0.0.1 | ||
*/ | ||
public class TypeAliasSimpleBean { | ||
|
||
/** | ||
* 名称 | ||
*/ | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |