开发者

Conversion strategies for bind variables

A Spring JDBC question: I use a lot of objects as bind variables which are not automatically mapped to their JDB开发者_运维问答C equivalents, e.g. jdbctemplate.query(sql, foo, bar, wee) with foo, bar and wee being instances of objects which are not covered by the JDBC type autoconversion.

Can anyone on SO suggest a best practice for a conversion strategy for such cases? Most cases would boil down to call toString() on the instances anyways.


I'm not sure that I understand the question, but I believe there are two parts to this binding and conversion problem:

  1. Binding from UI to Java objects is handled using the Spring data binding API. That can handle binding to both standard Java types and your own custom types (if you write the appropriate PropertyEditors).
  2. Binding your Java objects to JDBC depends on the underlying implementation. If you're using Spring Simple JDBC, you'll write ParameterizedRowMappers to get data out of ResultSets and into your objects. If you're using Hibernate, you'll have ORM mapping files. iBatis has its own way to manage it.

I don't understand what "Most cases would boil down to call toString() on the instances anyways" means.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜