spring-将文本框中的定界字符串绑定到Collection

前端之家收集整理的这篇文章主要介绍了spring-将文本框中的定界字符串绑定到Collection 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个< form:input type =“ text” />可以采用多个值的元素,每个值均以分号分隔.例如,可以采用诸如Mike; Jack; Bob之类的值.

如何为< input>绑定/传递这种类型的值到Collection< String>在Spring 3 MVC中?

最佳答案
您可以注册属性编辑器:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(Collection.class,new DelimitedCollectionStringEditor());
}

编辑器必须在其中扩展PropertyEditorSupport的地方

猜你在找的Spring相关文章