[英]Using spring boot thymeleaf : Display image and other information in a table at front end
[英]Display list of information in separate divs using thymeleaf and spring
如果問題可能過於籠統或太簡單,請事先道歉,但這是我第一次使用Spring。
我想做的事情如下:我有一個儀表板,該儀表板具有3列和5行。 每個div都有以下信息:名稱和分數。
我的應用程序具有以下模型:
public class Client{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "CLIENT_ID")
private Long id;
private String name;
private String lastName;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
@JsonManagedReference
private List<SurveyData> survey= new ArrayList<SurveyData>();
private char gender;
}
public class SurveyData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SURVEY_ID")
private Long Id;
@ManyToOne
@JsonBackReference
@JoinColumn(name = "client_id")
public Client client;
@OneToOne(cascade=CascadeType.ALL)
@JsonManagedReference
@JoinColumn(name = "surveyresult_id")
private SurveyResults surveyResults;
}
public class SurveyResults{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SURVEYRESULT_ID")
private Long Id;
private Double score;
}
因此,我想在列上顯示的是SurveyResults上的客戶名稱,姓氏和分數。
像這樣的東西:
按分數排序,降序選擇得分最高的前5名並顯示
現在我知道查詢將在存儲庫中進行。 但是,以列表或其他最佳方式返回的結果將如何在thymeleaf html文件中顯示?
如果我感到困惑或問題很簡單,我再次感到抱歉。我只需要一些指導,了解什么是最佳實踐以及如何實現我想做的事情。
<div class="col-md-12">
<div class="row">
<div class="col-sm-2">
<h3>#1</h3>
</div>
<div class="col-sm-3">
<img>
</div>
<div class="col-sm-7">
<h4 style="color: black;">
<b>NAME</b>
</h4>
<p style="font-size: 11px;">
Score: <b>SCORE from db</b>
</p>
</div>
</div>
<br />
<div class="row ">
<div class="col-sm-2">
<h3>#2</h3>
</div>
<div class="col-sm-3">
<img></div>
<div class="col-sm-7">
<h4 style="color: black;">
<b>NAME </b>
</h4>
<p style="font-size: 11px;">
Score: <b>SCORE from db</b>
</p>
</div>
</div>
....repeated for several rows
您可以使用Thymeleaf迭代器進行操作,如下所示:
<div class="row" th:each="c : ${clients}">
<div class="col-md-12">
<h2 th:text=" |${c.name}, ${c.lastName}| "></h2>
<table class="table">
<thead>
<tr><th>Score</th></tr>
</thead>
<tbody>
<tr th:each= " s : ${c.surveyResults}">
<td th:text=" ${s.score}"></td>
</tr>
</tbody>
</table>
</div>
</div>
因此,使用上面的代碼,您將為每個客戶提供一個部分,並在其下提供一個分數表。 確保在模型屬性clients
設置了client信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.