Spring SpEL-空值比较
我正在尝试将spring版本从3.0.5升级到3.2.11 当表达式比较空值时,我遇到了SpEL问题,如下所示:Spring SpEL-空值比较,spring,spring-el,Spring,Spring El,我正在尝试将spring版本从3.0.5升级到3.2.11 当表达式比较空值时,我遇到了SpEL问题,如下所示: new SpelExpressionParser().parseExpression("null < 7").getValue(); 版本3.2.11 public int compare(Object left, Object right) throws SpelEvaluationException { // If one is null, check if t
new SpelExpressionParser().parseExpression("null < 7").getValue();
public int compare(Object left, Object right) throws SpelEvaluationException {
// If one is null, check if the other is
if (left == null) {
return right == null ? 0 : -1;
} else if (right == null) {
return 1; // left cannot be null
}
new SpelExpressionParser().parseExpression("7 < null").getValue();
new SpelExpressionParser().parseExpression(“7
将导致:
- 是的,当使用版本3.0.5时,由于我的意见,这是不正确的
- 如果使用版本3.2.11,则为false
当使用,==,=运算符与另一个非空值进行比较时,空值比较是否假定为真?这不是错误,这是Spring团队的设计行为 从: 与null的大于/小于比较遵循一个简单的规则:null在这里被视为无(即不为零)。因此,任何其他值始终大于null(X>null始终为true),并且任何其他值都不小于零(X
" first == null ? false : second == null ? false : first < second "
“first==null?false:second==null?false:first
" first == null ? false : second == null ? false : first < second "