Skip to content

Commit dc0e799

Browse files
author
shlomysheps
committed
task springframeworkguru#4 add publisher entity
1 parent ffd4b32 commit dc0e799

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package guru.springframework.spring6webapp.controllers;
2+
3+
4+
import guru.springframework.spring6webapp.services.AutorService;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
9+
@Controller
10+
public class AuthorController {
11+
private final AutorService autorService;
12+
13+
14+
public AuthorController(AutorService autorService) {
15+
this.autorService = autorService;
16+
}
17+
@RequestMapping("/authors")
18+
public String getAuthors(Model model) {
19+
20+
model.addAttribute("authors", autorService.findAll());
21+
22+
return "authors";
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package guru.springframework.spring6webapp.services;
2+
3+
import guru.springframework.spring6webapp.domain.Author;
4+
import guru.springframework.spring6webapp.repositories.AuthorRepository;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
public class AuthorServiceImpel implements AutorService {
9+
public AuthorServiceImpel(AuthorRepository authorRepository) {
10+
this.authorRepository = authorRepository;
11+
}
12+
13+
private final AuthorRepository authorRepository;
14+
15+
16+
@Override
17+
public Iterable<Author> findAll() {
18+
return authorRepository.findAll();
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package guru.springframework.spring6webapp.services;
2+
3+
import guru.springframework.spring6webapp.domain.Author;
4+
5+
6+
7+
public interface AutorService {
8+
9+
Iterable<Author> findAll();
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<meta charset="UTF-8"/>
5+
<title>Spring Framework Guru</title>
6+
</head>
7+
<body>
8+
<h1>Authors List</h1>
9+
10+
<table>
11+
<tr>
12+
<th>ID</th>
13+
<th>Author First Name</th>
14+
<th>Author Last Name</th>
15+
</tr>
16+
<tr th:each="author : ${authors}">
17+
<td th:text="${author.id}">123</td>
18+
<td th:text="${author.firstName}"> Spring in Action</td>
19+
<td th:text="${author.lastName}">Wrox</td>
20+
</tr>
21+
</table>
22+
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)