spring-framework
spring-framework copied to clipboard
Introduce RowMapper with automatic binding to fields
BeanPropertyRowMapper
requires setters being present. Which is fine if you have some.
But if you only have a simple dto class for some reason, and want to make use of the mapper, it requires to create setters just for that.
It would be nice if we could have some DirectFieldRowMapper
additionally, similar to:
https://gist.github.com/stianl/6629122#file-directfieldrowmapper
Spring already allows direct field mapping for mvc with DataBinder.initDirectFieldAccess()
.
So why not providing a direct mapper also for jdbc beans, that can simply operate on public
fields?
Are you familiar with org.springframework.jdbc.core.DataClassRowMapper
introduced in Spring Framework 5.3?
Does the "data class constructor with named parameters corresponding to column names" support meet your needs?
No, as far as I understood the DataClassRowMapper
only adds the ability to let the mapper create the object using a constructor. If you have a dto with public fields, you usually won't have a constructor matching all the fields.
Like, if the db row has 20 columns, you would have to introduce a 20 column constructor to make it work. This is no advantage over creating 20 setters.
Like, if the db row has 20 columns, you would have to introduce a 20 column constructor to make it work. This is no advantage over creating 20 setters.
Sure. There's no real benefit in that.
We've assigned this proposal to the 5.x Backlog for potential inclusion in 5.3.x
Would still be great if that feature could get some investigation.