NamedParameterJdbcTemplate: add methods to simplify usage when no parameter is needed [SPR-10256]

Michael Isvy opened SPR-10256 and commented

When working with NamedParameterJdbcTemplate, we typically inject an instance of it in a DAO/Repository and use it in 10-20 methods that require accessing the database.
Most of those methods use parameters (which is why we use a NamedParameterJdbcTemplate). However, among the 20 methods inside my DAO, it's common that I have 3-4 of them that use SQL queries without parameters.

In that case, the syntax could be improved.

We currently do:

return this.namedParameterJdbcTemplate.query(
				"SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(),
				ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));

Inside NamedParameterJdbcTemplate, we could create some methods that do not take a HashMap as a parameter. We would then do instead:

return this.namedParameterJdbcTemplate.query(
				"SELECT id, name FROM types ORDER BY name", ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));

Note: in the first code sample, replacing the empty HashMap with null is not an option because the method call then becomes ambiguous as 2 methods could be selected.


Referenced from: commits 3fa6723