[solved] list Size() = 1 but all elements are null

Come on, old tie, do this code 2022-05-14 13:41:16 阅读数:159

solvedlistsizeelementsnull

background :

Use mybatis Aggregate function in (max()avg()) Inquire about SQL sentence , Load the returned results List aggregate

The following method is used to determine the null value :

if (CollectionUtils.isNotEmpty(list)) {

return xxx;
}

The result is , No matter what Whether there are values in the database , Return is not empty .

further debug Find out , list.size() = 1, but List The median value is empty , Show All elements are null

Question why :

Used MySQL Aggregate function in , These are summation functions SUM()、 Find the average function AVG()、 Maximum function MAX()、 Minimum function MIN() And counting functions COUNT, Which leads to size = 1, But when the result is empty , The specific reason is unknown , Subsequent updates ..

terms of settlement :

Use the following method to judge the blank

if (CollectionUtils.isNotEmpty(list) && list.get(0) != null) {

return xxx;
}
版权声明:本文为[Come on, old tie, do this code]所创,转载请带上原文链接,感谢。 https://qdmana.com/2022/134/202205141323254131.html