有没有一种通用的方法来获取MapRow的ResultsSet中的列

编程入门 行业动态 更新时间:2024-10-26 19:38:01
本文介绍了有没有一种通用的方法来获取MapRow的ResultsSet中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用SimpleJdbcTemplate,例如,我有这样的内容:

I am using SimpleJdbcTemplate and for example I have something like this:

@Override public Variant mapRow(ResultSet rs, int rowNum) throws SQLException

然后我通过如下代码行从此结果集中获取值:

then I am getting the values from this result set with lines of code like this:

variant.setName(rs.getString("variant_name"));

所以我必须查看我的表,看看我应该为每一列使用哪种类型,-在此示例中为String的getString-...所以我将拥有getString,getLong,getInt,...

so I have to look at my table, see what type should I use for each column, - getString for String in this example - ...so I will have getString, getLong, getInt,...

我想知道是否存在一种更通用的方式来从结果集中获取这些值,而无需指定正确的类型,并希望Spring JDBC处理这些通用类型上的装箱/拆箱操作

I was wondering if there a more generic way of getting these values from result set without the need to specify the correct type and hope that Spring JDBC takes care of some boxing/unboxing on these generic types

推荐答案

如果要将JDBC结果映射到对象模型,则必须忍受这一点.使用JDBC就是这样.

If you want to map JDBC results to your object model, then you're going to have to live with doing that. That's the deal when you use JDBC.

如果您想要更高级的内容,包括列到属性的映射,那么您需要一个更好的工具.您可以全程使用Hibernate,但这会带来很多负担,并且解决的每个问题都会带来10个新问题.

If you want something more high level, including column-to-property mapping, then you need a better tool. You could go the whole hog and use Hibernate, but that carries a whole load of baggage, and presents 10 new problems for every one it solves.

看看 MyBatis (以前称为iBatis).这是一个相当基本的框架,用于将JDBC结果集映射到javabeans,并支持连接/语句管理.Spring 提供了对iBatis 2的支持,但不再支持iBatis 2本身.现成的Spring不支持新的MyBatis 3.x,但是MyBatis项目提供了自己的Spring集成.

Have a look at MyBatis (formerly known as iBatis). This is a pretty basic framework for mapping JDBC result sets to javabeans, with connection/statement management backed in. Spring provides support for iBatis 2, but iBatis 2 itself is no longer supported. The new MyBatis 3.x isn't supported by Spring out-of-the-box, but the MyBatis project does provide it's own Spring integration.

更多推荐

有没有一种通用的方法来获取MapRow的ResultsSet中的列

本文发布于:2023-08-07 19:51:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法来   MapRow   ResultsSet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!