The Spring MVC documentation just isn't quite there. It is pretty basic, and doesn't really help with some common medium difficulty scenarios. The one I am documenting today is how to take a typical model (with lists of dependent objects), show it in a form, and get the graph back upon submission...
Rather than go through the entire thought process from beginning to end, I am going to show the end state and then explain the major glue points that make everything work. The assumption is that you have an ok understanding of Spring MVC.
The model
Here's a simple model for the illustration. There is an object named Grid which has a list of Block objects..
the LazyList class is the key here. This is in from the commons-collections package. I'll talk about why this is key later.
Rather than go through the entire thought process from beginning to end, I am going to show the end state and then explain the major glue points that make everything work. The assumption is that you have an ok understanding of Spring MVC.
The model
Here's a simple model for the illustration. There is an object named Grid which has a list of Block objects..
public class Grid {
private List blocks =
LazyList.decorate(
new ArrayList(),
FactoryUtils.instantiateFactory(Block.class));
public List getBlocks() {
return blocks;
}
public void setBlocks(List list) {
blocks = list;
}
}
the LazyList class is the key here. This is in from the commons-collections package. I'll talk about why this is key later.
public class Block {
private String id, description;
public String getDescription() {
return description;
}
public String getId() {
return id;
}
public void setDescription(String string) {
description = string;
}
public void setId(String string) {
id = string;
}
}
本文介绍如何在Spring MVC中处理包含依赖对象列表的复杂模型。通过使用commons-collections包中的LazyList类来简化操作,并详细解释了实现过程中的关键粘合点。
1484

被折叠的 条评论
为什么被折叠?



