Java 绑定映射时调用自定义构造函数
绑定列表时,我可以通过在AutoPopulationGlist中使用自定义ElementFactory以以下方式控制对象的实例化方式(对于Instance,使用多个参数调用构造函数):Java 绑定映射时调用自定义构造函数,java,spring,data-binding,collections,spring-mvc,Java,Spring,Data Binding,Collections,Spring Mvc,绑定列表时,我可以通过在AutoPopulationGlist中使用自定义ElementFactory以以下方式控制对象的实例化方式(对于Instance,使用多个参数调用构造函数): public class Foo{ private List<NestedFoo> nested = new AutoPopulatingList<NestedFoo>(new ElementFactory<NestedFoo>() { @Overri
public class Foo{
private List<NestedFoo> nested = new AutoPopulatingList<NestedFoo>(new ElementFactory<NestedFoo>() {
@Override
public NestedFoo createElement(int index) throws ElementInstantiationException {
return new NestedFoo(index);
}
});
}
公共类Foo{
private List nested=new autopopulationglist(new ElementFactory()){
@凌驾
公共NestedFoo createElement(int索引)抛出ElementInstanceionException{
返回新的NestedFoo(索引);
}
});
}
当集合是一个映射而不是一个列表时,有什么方法可以做类似的事情吗?我的意思是,当表单发送类似嵌套['fooParam']的内容时,我希望在映射为“自动增长”时使用fooParam调用构造函数
谢谢。我不知道Spring中有什么解决方案,但是的类允许您创建计算地图:
ConcurrentMap<Key, Graph> graphs = new MapMaker()
.concurrencyLevel(4)
.softKeys()
.weakValues()
.maximumSize(10000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.makeComputingMap(
new Function<Key, Graph>() {
public Graph apply(Key key) {
// this is where your values are created on demand
return createExpensiveGraph(key);
}
});
ConcurrentMap graphs=newmapmaker()
.1级(4)
.软键()
.weakValues()
.最大尺寸(10000)
.expireAfterWrite(10,时间单位:分钟)
.makeComputingMap(
新函数(){
公共图形应用(密钥){
//这是根据需要创建价值的地方
返回createExpensiveGraph(键);
}
});
参考资料:
顺便说一句,它有一个相似的特点: