I am new to spring world, in above code i understand query but i don't get why "new MapSqlParameterSource("username" ,username)" is used?
public boolean exists(String username) {
return jdbc.queryForObject("select count(*) from users where username=:username",
new MapSqlParameterSource("username" ,username),Integer.class)>0; }
what is the purpose of using it?
Thanks in advance
It is because some developers do not like use ?
in a sql sentence.
This ?
is named or referred how (mostly the first):
Therefore Spring offers the same approach, it such as how Hibernate/JPA does with :parameter
, it through the MapSqlParameterSource
class.
I suggest you do a research about RowMapper<T>
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With