开发者

How do I use Spring's IdToEntityConverter to do my Entity Type Conversion during form binding?

I'm sick of writing extending PropertyEditorSupport for every 开发者_开发知识库single Entity in my system.

I notice that Spring 3.0 has an IdToEntityConverter, but there is really not much documentation on how to use it.

Please comment on the best generic way to convert between id and entity.


IdToEntityConverter is an internal Spring class. It's non-public, which is why it doesn't appear in the javadoc, but it's registered by default in every context. The class comment says:

Converts an entity identifier to a entity reference by calling a static finder method on the target entity type.

For this converter to match, the finder method must be public, static, have the signature find[EntityName]([IdType]), and return an instance of the desired entity type.

So if you're trying to bind entity class X, then X must have a public static findX(id), or something similar, on class X.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜