我在尝试使用 Spring MVC 填充 JSP 中的选择框时收到 PropertyNotFoundException。我(认为)我的所有实现都是正确的。谁能指出我是否错过了什么。
下面是我的代码片段:
JSP 中的 Spring MVC
<form:select path="${field.fieldCode}">
<form:options items="${states.code}" />
</form:select>
国家和州级
Class State {
private Long id;
private Country country;
private String code;
private String name;
}
Class Country {
....
private Set<State> states;
}
服务等级
@Transactional(readOnly=true)
@Service("domainGeoService")
public class DomainGeoServiceImpl implements DomainGeoService {
@Override
public Set<State> getStates() {
Country usa = (Country)sessionFactory.getCurrentSession().get(Country.class, 1L);
return usa.getStates();
}
}
Webflow 配置
<evaluate expression="domainGeoService.getStates()" result="viewScope.states"/>
**我得到的正是异常**
Caused by: javax.el.PropertyNotFoundException: Property 'code' not found on type org.hibernate.collection.PersistentSet
最佳答案
将 Spring MVC 更改为以下解决了该问题。
<form:select path="${field.fieldCode}" >
<form:option value="" label="** Select State **"></form:option>
<form:options items="${states}" itemValue="code" itemLabel="code"></form:options>
</form:select>
关于java - 使用 Spring MVC 显示 Set<State>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28836740/