使用 Spring MVC 显示集<State>
Display Set<State> using Spring MVC
我在尝试使用 Spring MVC 填充 JSP 中的 select 框时遇到 PropertyNotFoundException。我(认为)我的所有实施都是正确的。谁能指出我是否遗漏了什么。
下面是我的代码片段:
Spring JSP
中的 MVC
<form:select path="${field.fieldCode}">
<form:options items="${states.code}" />
</form:select>
国家和州class
Class State {
private Long id;
private Country country;
private String code;
private String name;
}
Class Country {
....
private Set<State> states;
}
服务Class
@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
你有没有导入错误的包?
您是否明确导入了 org.hibernate.collection.PersistentSet
以支持 java.utils.Set
,或者您的 IDE 是否在 table 下对您进行了快速攻击?
将 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>
我在尝试使用 Spring MVC 填充 JSP 中的 select 框时遇到 PropertyNotFoundException。我(认为)我的所有实施都是正确的。谁能指出我是否遗漏了什么。
下面是我的代码片段:
Spring JSP
中的 MVC<form:select path="${field.fieldCode}">
<form:options items="${states.code}" />
</form:select>
国家和州class
Class State {
private Long id;
private Country country;
private String code;
private String name;
}
Class Country {
....
private Set<State> states;
}
服务Class
@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
你有没有导入错误的包?
您是否明确导入了 org.hibernate.collection.PersistentSet
以支持 java.utils.Set
,或者您的 IDE 是否在 table 下对您进行了快速攻击?
将 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>