File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed
java/guru/springframework/spring6webapp Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments