Now we can give UserRowMapper to named JDBC template and it will map the result of the query into a new instance of User class.
NamedParameterJdbcTemplate namedJdbcTemplate =Grails.get(NamedParameterJdbcTemplate)Map params = [id:1]UserRowMapper mapper =newUserRowMapper()User usersY =namedJdbcTemplate.queryForObject("SELECT * FROM User WHERE id=:id", params, mapper)layout.addComponent(newLabel(usersY.firstName))
Use BeanPropertyRowMapper in case your domain model matches name of columns in a database table. Then you do not have to create mappers and data from your queries will automatically transfered to instance of a domain class.