Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Got a question about your Spring Framework 5 course? [Checkout these FAQs!](http
### Recommended Versions
| Recommended | Reference | Notes |
| ----------- | --------- | ----- |
| Oracle Java 8 JDK | [Download](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) | Java 11 is okay, see notes about Java [on the course wiki](https://github.com/springframeworkguru/spring5webapp/wiki/Java-Version) |
| Oracle Java 11 JDK | [Download]([https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html)) | Java 8 or Java 17 may also be used. |
| IntelliJ 2018 or Higher | [Download](https://www.jetbrains.com/idea/download/) | Ultimate Edition recommended. Students can get a free 120 trial license [here](https://github.com/springframeworkguru/spring5webapp/wiki/Which-IDE-to-Use%3F#how-do-i-get-the-free-120-day-trial-to-intellij-ultimate) |
| Maven 3.6.0 or higher | [Download](https://maven.apache.org/download.cgi) | [Installation Instructions](https://maven.apache.org/install.html)|
| Gradle 4.8 or higher | [Download](https://gradle.org/install/) | **Note:** Use Version 5 or higher if using Java 11 |
Expand All @@ -25,7 +25,7 @@ Got a question about your Spring Framework 5 course? [Checkout these FAQs!](http

## All Spring Framework Guru Courses
### Spring Framework 5
* [Spring Framework 5: Beginner to Guru](https://www.udemy.com/testing-spring-boot-beginner-to-guru/?couponCode=GITHUB_REPO) - Get the most modern and comprehensive course available for the Spring Framework! Join over 8,200 over Guru's in an Slack community exclusive to this course! More than 3,700 students have given this 53 hour course a 5 star review!
* [Spring Framework 5: Beginner to Guru](https://www.udemy.com/testing-spring-boot-beginner-to-guru/?couponCode=GITHUB_REPO) - Get the most modern and comprehensive course available for the Spring Framework! Join over 17,200 over Guru's in an Slack community exclusive to this course! More than 5,700 students have given this 53 hour course a 5 star review!
* [Spring Boot Microservices with Spring Cloud Beginner to Guru](https://www.udemy.com/course/spring-boot-microservices-with-spring-cloud-beginner-to-guru/?referralCode=6142D427AE53031FEF38) - Master Microservice Architectures Using Spring Boot 2 and Cloud Based Deployments with Spring Cloud and Docker
* [Reactive Programming with Spring Framework 5](https://www.udemy.com/reactive-programming-with-spring-framework-5/?couponCode=GITHUB_REPO_SF5B2G) - Keep your skills razor sharp and take a deep dive into Reactive Programming!
* [Testing Spring Boot: Beginner to Guru](https://www.udemy.com/testing-spring-boot-beginner-to-guru/?couponCode=GITHUB_REPO_SF5B2G) - ** Best Selling Course** Become an expert in testing Java and Spring Applications with JUnit 5, Mockito and much more!
Expand All @@ -41,12 +41,8 @@ Got a question about your Spring Framework 5 course? [Checkout these FAQs!](http
* [Ready for Production with Spring Boot Actuator](https://www.udemy.com/ready-for-production-with-spring-boot-actuator/?couponCode=GITHUB_REPO_SF5B2G) - Learn how to leverage Spring Boot Actuator to monitor your applications running in production.

### Web Development with Spring Framework
* [Angular 4 Java Developers](https://www.udemy.com/angular-4-java-developers/?couponCode=GITHUB_REPO_SF5B2G) - Learn how to use Angular with Spring Boot. Two flaming hot technologies! This is the only course on Udemy where you can learn how to use JHipster to rapidly build your next application! Also, be sure to checkout the Slack community for this course!
* [Mastering Thymeleaf with Spring Boot](https://www.udemy.com/mastering-thymeleaf-with-spring/?couponCode=GITHUB_REPO_SF5B2G) - Once you learn Thymeleaf, you'll never want to go back to using JSPs for web development!

### Spring Framework 4
* [Spring Core](https://www.udemy.com/spring-core/) - Learn the core of Spring Framework 4!
* [Spring Core Advanced](https://www.udemy.com/spring-core-advanced-beyond-the-basics/?couponCode=GITHUB_REPO_SF5B2G) - Go beyond the basics! Learn about Aspect Oriented Programming, Spring Security, using Spring Events, JMS and more!

## Connect with Spring Framework Guru
* Spring Framework Guru [Blog](https://springframework.guru/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package guru.springframework.spring5webapp.bootstrap;

import guru.springframework.spring5webapp.domain.Author;
import guru.springframework.spring5webapp.domain.Book;
import guru.springframework.spring5webapp.domain.Publisher;
import guru.springframework.spring5webapp.repositories.AuthorRepository;
import guru.springframework.spring5webapp.repositories.BookRepository;
import guru.springframework.spring5webapp.repositories.PublisherRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class BootStrapData implements CommandLineRunner {

public static final String PUBLISHER_ADDRESS = "Sayram 5";
public static final String PUBLISHER_CITY = "Tashkent";
public static final String PUBLISHER_STATE = "Tashkent";
public static final String PUBLISHER_ZIP_CODE = "100000";
public static final String BOOK_NAME = "Java book";
public static final String ISBN = "12345";
private final BookRepository bookRepository;
private final AuthorRepository authorRepository;
private final PublisherRepository publisherRepository;

public BootStrapData(BookRepository bookRepository, AuthorRepository authorRepository, PublisherRepository publisherRepository) {
this.bookRepository = bookRepository;
this.authorRepository = authorRepository;
this.publisherRepository = publisherRepository;
}
@Override
public void run(String... args) {
Author saahon = createAuthor();
Book book = createBook();

saahon.getBooks().add(book);
book.getAuthors().add(saahon);
authorRepository.save(saahon);

Publisher publisher = createPublisher(saahon);
publisherRepository.save(publisher);

book.setPublisher(publisher);
bookRepository.save(book);

System.out.println("Started in Bootstrap");
System.out.println("saved books: " + bookRepository.count());
System.out.println("saved authors: " + authorRepository.count());
System.out.println("saved publishers: " + publisherRepository.count());
}

private static Publisher createPublisher(Author saahon) {
Publisher publisher = new Publisher();
publisher.setName(saahon.getFirstName());
publisher.setAddressLine1(PUBLISHER_ADDRESS);
publisher.setCity(PUBLISHER_CITY);
publisher.setState(PUBLISHER_STATE);
publisher.setZip(PUBLISHER_ZIP_CODE);
return publisher;
}
private static Book createBook() {
Book book = new Book();
book.setTitle(BOOK_NAME);
book.setIsbn(ISBN);
return book;
}

private static Author createAuthor() {
Author saahon = new Author();
saahon.setFirstName("Saidakramov");
saahon.setLastName("Avaz");
return saahon;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package guru.springframework.spring5webapp.controller;

import guru.springframework.spring5webapp.repositories.AuthorRepository;
import guru.springframework.spring5webapp.repositories.BookRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AuthorController {

private final AuthorRepository authorRepository;

public AuthorController(AuthorRepository authorRepository) {
this.authorRepository = authorRepository;
}

@RequestMapping("/authors")
public String getBooks(Model model) {
model.addAttribute("authors", authorRepository.findAll());
return "authors/list";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package guru.springframework.spring5webapp.controller;

import guru.springframework.spring5webapp.repositories.BookRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class BookController {

private final BookRepository bookRepository;

public BookController(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}

@RequestMapping("/books")
public String getBooks(Model model) {
model.addAttribute("books", bookRepository.findAll());
return "books/list";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package guru.springframework.spring5webapp.domain;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String firstName;
private String lastName;

@ManyToMany(mappedBy = "authors")
private Set<Book> books = new HashSet<>();

public Author() {
}

public Author(Long id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Set<Book> getBooks() {
return books;
}

public void setBooks(Set<Book> books) {
this.books = books;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Author author = (Author) o;

return Objects.equals(id, author.id);
}

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}

@Override
public String toString() {
return "Author{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", books=" + books +
'}';
}
}
98 changes: 98 additions & 0 deletions src/main/java/guru/springframework/spring5webapp/domain/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package guru.springframework.spring5webapp.domain;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String title;
private String isbn;

@ManyToMany
@JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "book_id"), inverseJoinColumns = @JoinColumn(name = "author_id"))
private Set<Author> authors = new HashSet<>();

@ManyToOne
private Publisher publisher;

public Book() {
}

public Book(Long id, String title, String isbn, Set<Author> authors, Publisher publisher) {
this.id = id;
this.title = title;
this.isbn = isbn;
this.authors = authors;
this.publisher = publisher;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
this.isbn = isbn;
}

public Set<Author> getAuthors() {
return authors;
}

public void setAuthors(Set<Author> authors) {
this.authors = authors;
}

public Publisher getPublisher() {
return publisher;
}

public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Book book = (Book) o;

return Objects.equals(id, book.id);
}

@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}

@Override
public String toString() {
return "Book{" +
"id=" + id +
", title='" + title + '\'' +
", isbn='" + isbn + '\'' +
'}';
}
}
Loading