推荐使用ParameterizedRowMapper或RowMapper [英] ParameterizedRowMapper is recommended or RowMapper

查看:136
本文介绍了推荐使用ParameterizedRowMapper或RowMapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring JDBC的新手,正在处理给定的任务,查看我们已经让我的队友使用过RowMapper的代码,但是我正在做一些Google搜索,并且看到一些教程正在使用ParameterizedRowMapper,所以我想知道是否有是使用一种而不是另一种的任何好处或良好实践,以及您使用该技术背后的技术思想...

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...

谢谢.

推荐答案

在Spring 3.0之前,大多数API都不使用泛型,因为Java 1.5并不是必需的.结果,出现了一个不支持泛型的RowMapper和一个通过扩展RowMapper并添加泛型参数来支持泛型的ParameterizedRowMapper.从Spring 3.0开始,大多数API已更新为支持泛型.如果您实际查看ParameterizedRowMapper的当前(3.0或更高版本)定义,那么它只是简单地扩展RowMapper,并且不向该定义添加任何内容以允许向后兼容.因此,您几乎可以使用参数化的RowMapper,也可以不使用参数化的RowMapper,而无需使用ParameterizedRowMapper.

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.

这篇关于推荐使用ParameterizedRowMapper或RowMapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆