I have the following db table:
CREATE TABLE authors
(
id INT AUTO_INCREMENT PRIMARY KEY,
authorName VARCHAR(250) NOT NULL
);
I want to print our the authors as follows:
A
- Anselma McKennan
B
- Berty Gandley
- Bette-ann Askem
C
- Clerc Djakovic
- Cristie Isacsson
D
- Dannie Glidder
- Darcey Rohmer
- Dom Robuchon
Currently I have by thymleaf template printing as follows and I do not want to print out the Alphabet LETTER each time in front of the author:
A
- Anselma McKennan
B
- Berty Gandley
B
- Bette-ann Askem
C
- Clerc Djakovic
C
- Cristie Isacsson
D
- Dannie Glidder
D
- Darcey Rohmer
D
- Dom Robuchon
My controller:
@GetMapping("/index.html")
public String mainPage(Model model) {
model.addAttribute("authorsData", bookService.getAuthorData());
return "/authors/index";
}
My service:
public List<Author> getAuthorData() {
List<Author> authors = jdbcTemplate.query("SELECT id, authorName from authors ORDER BY authorName", (ResultSet rs, int rowNum) -> {
Author author = new Author();
author.setId(rs.getInt("id"));
author.setAuthorName(rs.getString("authorName"));
return author;
});
return new ArrayList<>(authors);
}
My Thymeleaf code is as follows:
<div class="Authors-block" th:each="author : ${authorsData}" >
<h2 class="Authors-title" id="a" th:text="${author.getAuthorName().charAt(0)}">
</h2>
<div class="Authors-letter">
<div class="Authors-item"><a href="/authors/slug.html" th:text="${author.getAuthorName()}"></a>
</div>