【问题标题】:Displaying list in a list JSP Page在列表 JSP 页面中显示列表
【发布时间】:2015-08-27 06:37:15
【问题描述】:

我正在尝试显示一个列表,该列表中的每个对象都有另一个我必须显示的列表,值即将出现但没有显示,如果有人能识别我在做什么,下面是我尝试过的代码错了,会很有帮助的。我正在使用 Spring MVC,但我认为它与此错误无关,将不胜感激。

    @Entity
@Table(name="FILE_TRACKING_MANAGEMENT")
@NamedQuery(name="FileTrackingManagement.findAll", query="SELECT f FROM FileTrackingManagement f")
{

   @OneToMany(mappedBy="fileTrackingManagement")
    private List<FileNoting> fileNotings;

    //bi-directional many-to-one association to FileTrackingFile
    @OneToMany(mappedBy="fileTrackingManagement")
    private List<FileTrackingFile>  fileTrackingFiles;

    }

我的控制器类:

@RequestMapping("viewMarkedFiles/list")
    public ModelAndView viewMarkedFiles(Model model)
    {
        List<FileTrackingManagement> markedFileList=  fileService.getList();
        //model.addAttribute("markedFileList", markedFileList);

        return new ModelAndView("viewMarkedFiles", "markedFileList", markedFileList);
    }

我的 JSP 页面:

<table border="1" bgcolor="black" width="600px">
    <c:forEach items="${markedFileList}" var="markedFileVal">
    <%--                <c:set var="fileNotings" value="${jobs[i.index].jobId}"/> --%>
                        <tr
                            style="background-color: white; color: black; text-align: center;"
                            height="30px">

                            <td><c:out value="${markedFileVal.diarynumber}" />
                            <td><c:out value="${markedFileVal.subject}" />
                            <td>

                            </td>
                            <td>

                            </td>
                            <td>
                            <c:forEach items="${markedFileList.fileNotings}" var="filenotings">
                            <c:out value="${filenotings.notingData}" /></c:forEach>
                            </td>
</c:forEach>
</table>

它抛出这个异常:

45: <%--                        <c:out value="${fileVal.description}" /> --%>
46:                         </td>
47:                         <td>
48:                         <c:forEach items="${markedFileList.fileNotings}" var="filenotings">
49:                         <c:out value="${filenotings.notingData}" /></c:forEach>
50:                         
51:                         


Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "fileNotings"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)



at java.lang.Integer.parseInt(Unknown Source)

提前致谢

【问题讨论】:

  • 在你提出问题并得到答案后,不要完全改变你的问题。接受答案,然后针对您的其他问题提出另一个问题,至少在尝试过自己解决之后。我回滚到原来的问题。

标签: spring list jsp frontend jsp-tags


【解决方案1】:
<c:forEach items="${markedFileList}" var="markedFileVal">

所以,您正在遍历列表markedFileList。在标签主体内,当前元素是markedFileVal。

那你就做吧

<c:forEach items="${markedFileList.fileNotings}" var="filenotings">

所以你要从markedFileList.fileNotings 开始。但是markedFileList 是一个列表。它不是当前元素。你想要的是

<c:forEach items="${markedFileVal.fileNotings}" var="filenoting">

另外请注意,我从filenotings 中删除了最后的s。此变量指向单个文件注释。不是几个。

【讨论】:

  • 是的,感谢您指出我已经更新了我的问题,我看到了我犯的错误,但我的问题不是那个。我没有从数据库中加载值
  • 当你问你的问题时,当我回答它时,当两个人赞成我的回答时。更改问题会使答案变得无关紧要,并且对花时间阅读和回答您原始问题的人表示不尊重。
  • 对不起先生,我已经接受了答案。真的很抱歉给您带来不便
  • 是的@JBNizet,当我来到这里时,问题已更新为新问题,所以我想知道这个答案与问题有什么关系。
  • @NamanGala 对不起,我发现我的错误,不知道它会很快得到答复,因为我是新来的
【解决方案2】:

@OneToMany(fetch = FetchType.EAGER, mappedBy="fileTrackingManagement") 私有列表文件注解;

fetchType 的值默认是 Lazy,当我改变它的值时,它起作用了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    相关资源
    最近更新 更多