Java JdbcTemplate queryForList 在没有结果的情况下返回值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24797778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:53:22  来源:igfitidea点击:

JdbcTemplate queryForList return value in case of no results

javaspringjdbctemplate

提问by Reins

The question is pretty much summed up in the title. What will JdbcTemplate.queryForList() return when the query returns no results. Will it return an empty List or null value? I couldn't find a definitive answer from the documentation. Thanks in advance!

这个问题几乎总结在标题中。当查询没有返回结果时 JdbcTemplate.queryForList() 将返回什么。它会返回一个空列表或空值吗?我无法从文档中找到明确的答案。提前致谢!

采纳答案by Stephane Nicoll

The javadoc states that it will return

javadoc 声明它将返回

a List of objects that match the specified element type

If there's no element, the list is empty.

如果没有元素,则列表为空。

回答by Sachin Kumar

It will return an empty list. So you can test it with list.isEmpty(). It will return true in this case.

它将返回一个空列表。所以你可以用list.isEmpty(). 在这种情况下它将返回 true。