私はSpring、Thymeleaf、およびjOOQを初めて使用します。データベース ルックアップの結果を概要に表示したいと考えています。select().from(CONFIGURATIONS) をクエリすると、Thymeleaf ビューは問題なく動作します。しかし、ユーザー テーブルに結合して、ID だけでなくユーザーの名前を結果に追加しようとすると、エラーが発生します。
これは、Web ブラウザーのエラーです。
Mon Oct 10 16:04:17 CEST 2016 予期しないエラーが発生しました (タイプ = 内部サーバー エラー、ステータス = 500)。SpringEL 式を評価する例外: "config.name" (概要:37)
これはEclipseのエラーです:
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 7): プロパティまたはフィールド 'name' がタイプ 'org.jooq.impl.RecordImpl' のオブジェクトに見つかりません - おそらく公開されていませんか?
ビュー コードが間違っていることはわかりましたが、正しい property.field を取得するために "config.name" を何に変更すればよいかわかりません。
これは私のコントローラーです:
@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>