我有一个JSP页面...我在post处理程序中获得district.id ...我想通过转换器自动填充区域对象。我有很多实体类,所以我不想为所有的实体类写很多Converter。
<form:form commandName ="village" action="village.html" >
<label><fmt:message key="location.district"/></label>
<form:select path="district.id">
<form:options items="${districtList}" itemValue="id" itemLabel="districtName"/>
</form:select>
<input type = "submit" value="Save" class="submit-button" /> </form:form>
</form:form>我遵循这个link...but没有工作...:-( http://digitaljoel.nerd-herders.com/2011/06/15/spring-converterfactory-implementation/
请给我一些实际可行的例子。
发布于 2012-01-24 21:05:47
你有没有考虑过春季的BeanWrapper接口。这类似于commons-beanutils,
您可以将此接口与BeanWrapperImpl类一起使用,以从请求对象读取属性并填充关联的模型。
final BeanWrapper sourceBean = new BeanWrapperImpl(obj);
final PropertyDescriptor[] propertyDescriptors = sourceBean.getPropertyDescriptors();
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
// create a destinationBean
// iterate through each property from the sourceBean and set it to destinationBean.
}通过这种方式,您可以将字段值从一个bean复制到另一个bean,如果您有一个正在处理的请求对象,则可以查看struts2框架,否则请尝试将上面的代码与springconverters (可以转换基本类型)一起使用,并构建您自己的转换器。
https://stackoverflow.com/questions/8986483
复制相似问题