Skip to content

Commit

Permalink
vipshop#2 代码注释,解释为什么不适用Orika等。
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Jun 7, 2018
1 parent d44aa7b commit e38f725
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
- Tools

[GitHub](https://github.com/vipshop/vjtools)
[Java开发手册](standard/)
[Java Coding Guidelines](standard/)
2 changes: 1 addition & 1 deletion vjkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Maven:
|[Guava](https://github.com/google/guava) | 20.0 ||
|[Apache Common Lang](https://github.com/apache/commons-lang) | 3.7 ||
|[Slf4j](https://www.slf4j.org) | 1.7.25 ||
|[Dozer](http://dozermapper.github.io/) | 5.5.1 |Optional for BeanMapper |
|[Dozer](http://dozermapper.github.io/) | 5.5.1 |Optional for BeanMapper[选型过程](https://github.com/vipshop/vjtools/blob/master/vjkit/src/main/java/com/vip/vjtools/vjkit/reflect/BeanMapper.java) |

如果使用Optional的依赖,请参考pom文件在业务项目自行引入

Expand Down
21 changes: 11 additions & 10 deletions vjkit/src/main/java/com/vip/vjtools/vjkit/base/ValueValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
*
*/
public class ValueValidator {

/**
* 对目标值进行校验,并根据校验结果取值
* <br>使用示例(校验目标值是否大于0, 如果小于 0 则取值为 1)
* <br>ValueValidator.checkAndGet(-1, 1, Validator.INTEGER_GT_ZERO_VALIDATOR)</br>
*
* 使用示例(校验目标值是否大于0, 如果小于 0 则取值为 1)
*
* ValueValidator.checkAndGet(-1, 1, Validator.INTEGER_GT_ZERO_VALIDATOR)
*
* @param value 校验值
* @param defaultValue 校验失败默认值
* @param v 校验器
Expand All @@ -31,7 +34,11 @@ public static <T> T checkAndGet(T value, T defaultValue, Validator<T> v) {
* 对Properties值进行规则匹配的验证器
*/
public interface Validator<T> {

/**
* 校验值是否匹配
*/
boolean validate(T value);

/**
* 校验器: 数值配置不为null, 且大于0较验
*/
Expand Down Expand Up @@ -61,11 +68,5 @@ public boolean validate(String value) {
return "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
}
};

/**
* 值规则匹配方法实现
*/
boolean validate(T value);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
/**
* 实现深度的BeanOfClasssA<->BeanOfClassB复制
*
* 不要是用Apache Common BeanUtils进行类复制,每次就行反射查询对象的属性列表, 非常缓慢.
* 不要使用Apache Common BeanUtils进行类复制,每次就行反射查询对象的属性列表, 非常缓慢.
*
* orika性能更好,也不需要Getter函数与无参构造函数,但有潜在bug还没在社区版修复
* orika性能比Dozer快近十倍,也不需要Getter函数与无参构造函数
*
* Dozer有6.0版,但only for JDK8
* 但我们内部修复了的bug,社区版没有修复: https://github.com/orika-mapper/orika/issues/252
*
* 如果应用启动时有并发流量进入,可能导致两个不同类型的同名属性间(如Order的User user属性,与OrderVO的UserVO user)的复制失败,只有重启才能解决。
*
* 因此安全起见,在vjkit的开源版本中仍然使用Dozer。
*
* Dozer最新是6.x版,但only for JDK8,为兼容JDK7这里仍使用5.x版本。
*
* 注意: 需要参考POM文件,显式引用Dozer.
*/
Expand Down

0 comments on commit e38f725

Please sign in to comment.