简体   繁体   English

Spring JdbcTemplate 选择单列多行

[英]Spring JdbcTemplate Select Single column with multiple rows

I am using Spring JdbcTemplate and I couldn't find a proper way to execute select query which returns multiple rows.我正在使用 Spring JdbcTemplate,但找不到执行返回多行的选择查询的正确方法。 The select query has only one column.选择查询只有一列。 I can use **queryForList** but it returns a list of map which I feel is bit unnecessary just for a single column.我可以使用**queryForList**但它返回一个地图列表,我觉得这对于单个列来说是不必要的。

Query : select employeeName from employees;查询: select employeeName from employees;

Any better ways or a straight forward way to have a result of List<String> using jdbcTemplate form the above query?使用 jdbcTemplate 从上面的查询中获得List<String>结果的任何更好的方法或直接的方法?

There is this overloaded method queryForList which you can use.您可以使用这个重载方法queryForList

public <T> List<T> queryForList(String sql,
                                Class<T> elementType)
                         throws DataAccessException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM