我是使用 Spring、Thymeleaf 和 jOOQ 的新手。我想在概览中显示数据库查找的结果。当我只是查询 select().from(CONFIGURATIONS) 时,Thymeleaf 视图工作得很好。但是,当我想加入 User 表以将用户的名称添加到结果中,而不仅仅是 id 时,我得到一个错误。
这是网络浏览器中的错误:
2016 年 10 月 10 日星期一 16:04:17 CEST 出现意外错误(类型=内部服务器错误,状态=500)。评估 SpringEL 表达式的异常:“config.name”(概述:37)
这是 Eclipse 中的错误:
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 7): 在“org.jooq.impl.RecordImpl”类型的对象上找不到属性或字段“名称” - 也许不公开?
我知道我的视图代码是错误的,但我不知道应该将“config.name”更改为什么以获得正确的 property.field。
这是我的控制器:
@Controller
public class OverviewController
{
public ArrayList configurationList = new ArrayList();
@RequestMapping("/overview")
public String showConfigurationList(Model model)
{
model.addAttribute("configs", getConfigurations());
return "overview";
}
public ArrayList getConfigurations()
{
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword))
{
DSLContext create = DSL.using(conn, SQLDialect.POSTGRES_9_5);
Result<Record5<String, String, Timestamp, String, String>> result = create.select(CONFIGURATION.NAME, CONFIGURATION.VERSION, CONFIGURATION.DATE_MODIFIED, CONFIGURATION.AUTHOR_USER_ID, USER.NAME)
.from(USER).join(CONFIGURATION)
.on(CONFIGURATION.AUTHOR_USER_ID.equal(USER.ID)))
.fetch();
/*Result<Record> result = create.select()
.from(CONFIGURATION)
.fetch();*/
if(configurationList.isEmpty() == true)
{
for (Record5 r : result) {
configurationList.add(r);
}
}
}
catch (Exception e)
{
System.out.println("ERROR: " + e);
}
return configurationList;
}
这是 Thymeleaf 视图:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Nazza Mediator - Overview</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
<script src="http://code.jquery.com/jquery.js" />
<script src="webjars/bootstrap/3.3.7-1/js/bootstrap.min.js" />
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">Nazza Mediator</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li class="active"><a href="/overview">Configuration Overview</a></li>
</ul>
</div>
</nav>
<h3>Configuration Overview</h3>
<table class="table table-hover">
<tr>
<th>NAME</th>
<th>VERSION</th>
<th>DATE MODIFIED</th>
<th>AUTHOR</th>
</tr>
<tr th:each="config : ${configs}">
<td th:text="${config.name}"></td>
<td th:text="${config.version}"></td>
<td th:text="${config.dateModified}"></td>
<td th:text="${config.authorUserId}"></td>
</tr>
</table>
</body>
</html>