jdbctemplate count queryForInt 并传递多个参数

jdbctemplate count queryForInt and pass multiple parameters

如何在 jdbcTemplate queryForInt 中传递多个参数来获取计数。这个我试过了,

Integer count = this.jdbcTemplate
    .queryForInt("select count(name) from table_name where parameter1 = ? and parameter2 = ?", new Object[]{parameter1,parameter2});

但它显示 queryForInt 为罢工。

queryForInt() 和 queryForLong() 自版本 3.2.2 起已弃用(如有错误请指正)。要修复它,请将代码替换为 queryForObject(String, Class).

 this.jdbcTemplate.queryForObject(
                    sql, new Object[] { parameter1,parameter2 }, Integer.class);

根据spring docs

int queryForInt(String sql, Map args)

Deprecated. Query for an int passing in a SQL query using the named parameter support provided by the NamedParameterJdbcTemplate and a map containing the arguments.

int queryForInt(String sql, Object... args) Deprecated.

Query for an int passing in a SQL query using the standard '?' placeholders for parameters and a variable number of arguments. int queryForInt(String sql, SqlParameterSource args) Deprecated. Query for an int passing in a SQL query using the named parameter support provided by the NamedParameterJdbcTemplate and a SqlParameterSource containing the arguments.

根据 Spring Boot 的当前版本,

 this.jdbcTemplate.queryForObject(
                sql, new Object[] { parameter1,parameter2 }, Integer.class);

已弃用。所以试试下面给出的代码:

 this.jdbcTemplate.queryForObject(
                sql, Integer.class, new Object[] { parameter1,parameter2 });

参考 this Spring 文档。