您的位置:首页 > 产品设计 > UI/UE

JdbcTemplate.queryForList()方法各不同参数的详解

2015-06-28 16:33 603 查看
public <T> List<T> queryForList(

String sql,

Class<T> elementType,

Object... args

)throws DataAccessException


官方文档解释:

Parameters:

sql - SQL query to execute

elementType - the required type of element in the result list (for example, Integer.class)

args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale

我的理解

String sql, // 查询用的sql句

Object[] args, // sql句中的参数

int[] argTypes, // sql句中的参数的数据类型(java类型)

Class elementType // list装载结果的元数据类型

官方文档中最后的一个开变参数中讲到最后一个参数中可以包含SqlParameterValue对象,也就是说如果要通过这种方式给sql语句传参数,要将参数的类型转换成Object类型,如使用 Object[]{参数}这种方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: