Java 使用spring+hibernate在单个JSP文件中加载两个不同的SQL表

Java 使用spring+hibernate在单个JSP文件中加载两个不同的SQL表,java,spring,hibernate,jsp,Java,Spring,Hibernate,Jsp,对不起,我编辑了我的文章,因为我发布了一个误导性的错误 我在MySQL上有两个表,我试图在一个JSP页面中显示这两个表 我正在使用@RequestMapping来实现这一点 @RequestMapping(value = "/persons", method = RequestMethod.GET) public String listFolders(Model model) { model.addAttribute("folders", new Folders()); mode

对不起,我编辑了我的文章,因为我发布了一个误导性的错误

我在MySQL上有两个表,我试图在一个JSP页面中显示这两个表

我正在使用@RequestMapping来实现这一点

@RequestMapping(value = "/persons", method = RequestMethod.GET)
public String listFolders(Model model) {
    model.addAttribute("folders", new Folders());
    model.addAttribute("listFolders", this.foldersService.listFolders());
    return "person"; //name of the jsp page
}

@RequestMapping(value = "/folders", method = RequestMethod.GET)
public String listPersons(Model model) {
    model.addAttribute("person", new Person());
    model.addAttribute("listPersons", this.personService.listPersons());
    return "person"; //name of the jsp page
}
我需要在同一个JSP页面中显示这两个表,但是如果我尝试访问/文件夹,就会出现错误,因为它无法识别person表

我的JSP文件中的操作:

<c:if test="${!empty listPersons}">
<table class="tg">
<tr>
    <th width="80">Person ID</th>
    <th width="120">Person Name</th>
    <th width="120">Person Country</th>
</tr>
<c:forEach items="${listPersons}" var="person">
    <tr>
        <td>${person.id} </td>
        <td>${person.name}</td>
        <td>${person.country}</td>

    </tr>
</c:forEach>
</table>
以及:

错误:

Jun 06, 2017 5:53:07 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path 
[/CitelumApp] threw exception [java.lang.IllegalStateException: Neither 
BindingResult nor plain target object for bean name 'person' available as 
request attribute] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'person' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>
我的问题是:
有没有办法在同一个JSP页面上显示两个不同的SQL表?

为一个操作指定一个路由。因此,不能使用@RequestMappingvalue=/persons,method=RequestMethod.GET两次使用相同的值。请将人员更改为文件夹,例如listOfFolders上的文件夹

@RequestMapping(value = "/folder", method = RequestMethod.GET)

再加上Boukobba所说的,您应该真正查看错误消息。不能有两个具有相同url和相同请求方法的映射。DispatcherServlet无法确定将请求路由到哪个服务器。你可以考虑改变的是你的请求方法或者你的URL

编辑

@RequestMappingvalue=/person,method=RequestMethod.GET 公共字符串listFolders@ModelAttributepersonPerson Person,BindingResult personResult,@ModelAttributefolders文件夹,BindingResult文件夹错误,模型模型{ //您可以在JSP中作为新对象访问文件夹和人员 model.addAttributelistPersons,this.personService.listPersons; return person;//jsp页面的名称 } @RequestMappingvalue=/folders,method=RequestMethod.GET 公共字符串listFolders@ModelAttributepersonPerson Person,BindingResult personResult,@ModelAttributefolders文件夹,BindingResult文件夹错误,模型模型{ //您可以在JSP中作为新对象访问文件夹和人员 model.addAttributelistFolders,this.foldersService.listFolders; return person;//jsp页面的名称
}谢谢你的回复。我知道我可以改变。但是我总是在jsp文件中遇到错误,因为我调用了${person.name}和${person.id}之类的函数。所以,如果我把value/folder放进去,它就不会识别person表了。你可以发布你的jsp foreach循环的一部分吗?分享一些代码并详细说明你想要实现的目标。您可以尝试将所有model.addAttribute放在一个控制器映射中,并仅使用该控制器映射。我明白您的意思。但是我怎么能用一个GET调用两个不同的表呢?谢谢你抽出时间。
@RequestMapping(value = "/folder", method = RequestMethod.GET)