ParameterizedRowMapper is recommended or RowMapper

有些话、适合烂在心里 提交于 2019-12-11 07:40:08

问题


I am very new to Spring JDBC and working on a given task, looking at the codes we already have my teammates have used RowMapper, but I was doing some Googling and saw some tutorials are using ParameterizedRowMapper , so I was wondering if there is any benefit or good practice in using one rather than the other one and your technical thoughts behind that...

thanks.


回答1:


Prior to Spring 3.0, most APIs did not use generics because Java 1.5 wasn't a requirement. As a result, there was a RowMapper, that didn't support generics and ParameterizedRowMapper that did support generics by extending RowMapper and adding the generic parameter. As of Spring 3.0, most APIs were updated to support generics. If you actually look at the current (3.0 or greater) definition of ParameterizedRowMapper, it just simply extends RowMapper and adds nothing to the definition to allow for backward compatibility. Therefore, you can pretty much use RowMapper either parameterized or not and no need to use ParameterizedRowMapper.




回答2:


Right from the javadoc of ParameterizedRowMapper:

Extension of the RowMapper interface, adding type parameterization. As of Spring 3.0, this is equivalent to using the RowMapper interface directly.



来源:https://stackoverflow.com/questions/6960542/parameterizedrowmapper-is-recommended-or-rowmapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!