我正在使用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中的列
发布评论