【问题标题】:Spring MVC form:select selection from database issueSpring MVC 表单:从数据库问题中选择选择
【发布时间】:2021-07-18 16:16:56
【问题描述】:

我使用以下列表从控制器中填充了 JSP 中的下拉列表: ''' ''' thirdPartyOccupationId 来自实体类。我已将此下拉列表中的选定值保存在数据库中。现在,当我重新加载页面时,我没有看到 thirdPartyOccupationId 的值被选中。下拉列表仅按升序显示值列表。

例如,我使用下拉菜单将 5 保存为 db 中的thirdPartyOccupationId 的值。当我重新加载页面时,值 5 不是所选值。

同一段代码正在处理不同的字段,我不知道我错过了什么。

模型类:

ReportClass.java

    @JoinColumn(name = "third_party_occupation_id", referencedColumnName = "profession_id")
    @ManyToOne
    private Professions thirdPartyOccupationId;

Professions.java

        @Id
        @Basic(optional = false)
        @Column(name = "profession_id")
        private String professionId;
        @Column(name = "profession")
        private String profession;
        @OneToMany(mappedBy = "thirdPartyOccupationId")
        private Collection<ReportClass> reportClassCollection;

Controller.java

reportClass.setThirdPartyOccupationId(this.serviceManager.getProfessionsService().getByKey("123"));

model.addAttribute("reportClass", reportClass);
List<Professions> professionsList = serviceManager.getProfessionsService().findAll();
model.addAttribute("professionsList", professionsList);

感谢任何指针。

【问题讨论】:

    标签: spring jsp model-view-controller


    【解决方案1】:

    作为一种解决方法,我在 循环上方创建了一个新行,用于查看所选属性,即

    <tr>
        <td>
            <c:if test="${tipFe !=null}">${tipFe}</c:if>
            <c:if test="${tipFe eq null}">-</c:if>
        </td>
    </tr>
    
    <tr>
        <td>
            <c:forEach var="ltipfe" items="${ltipfe}">
            <option value=${ltipfe.tipfe}>${ltipfe.tipfe}</option>
            </c:forEach>
        </td>
    </tr>
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2014-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多