Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring SpEL-空值比较_Spring_Spring El - Fatal编程技术网

Spring 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

我正在尝试将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 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 "