【问题标题】:Display Set<State> using Spring MVC使用 Spring MVC 显示 Set<State>
【发布时间】:2015-03-04 17:15:03
【问题描述】:

我在尝试使用 Spring MVC 在 JSP 中填充选择框时遇到 PropertyNotFoundException。我(认为)我的所有实现都是正确的。任何人都可以指出我是否遗漏了什么。

下面是我的代码sn-p:

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

【问题讨论】:

    标签: java spring jsp spring-mvc spring-webflow


    【解决方案1】:

    将 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>
    

    【讨论】:

      【解决方案2】:

      您是否有任何机会导入了错误的包? 您是否明确导入了 org.hibernate.collection.PersistentSet 以支持 java.utils.Set,或者您的 IDE 是否在桌子底下对您进行了快速处理?

      【讨论】:

      • 不..我正在使用java.utils.Set
      猜你喜欢
      • 2021-03-09
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 2013-12-20
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多