Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1c79e3a
adding JPA example
springframeworkguru May 16, 2017
af9c8e8
adding JPA example
springframeworkguru May 16, 2017
80bf60b
adding bootstrap class
springframeworkguru May 16, 2017
acb22fb
completed assignment review
springframeworkguru May 17, 2017
336341e
adding book controller
springframeworkguru May 18, 2017
95e4dd0
adding book template
springframeworkguru May 18, 2017
423cecd
adding book template
springframeworkguru May 18, 2017
9b4b0f5
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
057a7e5
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
b3c04f4
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
7f628f2
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
52bbd03
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
405e6a6
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
248ef06
Updating Spring Boot Version
springframeworkguru Jun 19, 2017
ee5272e
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
a0f05ef
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
6648cfb
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
f9fd77f
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
451e547
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
3ed1e95
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
a6564a7
Updating Spring Boot Version
springframeworkguru Jul 31, 2017
57ad1ae
Corrected typo Worx to Wrox
tiagomestreteixeira Aug 24, 2017
b2dafef
Merge pull request #4 from tiagomestreteixeira/bootstrap
springframeworkguru Aug 24, 2017
3692bd4
adding equals, hash, and toString
springframeworkguru Sep 7, 2017
f7549bc
Merge branch 'equals' into spring-data-jpa
springframeworkguru Sep 7, 2017
f2aa6be
Merge branch 'equals' into bootstrap
springframeworkguru Sep 7, 2017
0b8c61e
Merge remote-tracking branch 'origin/bootstrap' into bootstrap
springframeworkguru Sep 7, 2017
587d5eb
Merge branch 'equals' into add-publisher-review
springframeworkguru Sep 7, 2017
1900f32
Merge branch 'equals' into adding-controller
springframeworkguru Sep 7, 2017
6d7ddf9
Merge branch 'equals' into adding-thymeleaf
springframeworkguru Sep 7, 2017
5318792
Merge branch 'equals' into display-authors
springframeworkguru Sep 7, 2017
f5f75c5
adding equals, hash, and toString
springframeworkguru Sep 7, 2017
28f68e9
Merge branch 'add-publisher-review' into adding-controller
springframeworkguru Sep 7, 2017
98359be
Merge branch 'adding-controller' into adding-thymeleaf
springframeworkguru Sep 7, 2017
7095a04
Merge branch 'adding-thymeleaf' into display-authors
springframeworkguru Sep 7, 2017
cade2fb
fix to Rod mapping
springframeworkguru Oct 4, 2017
6059ad1
Merge branch 'bootstrap' into add-publisher-review
springframeworkguru Oct 4, 2017
901d258
merge fix
springframeworkguru Oct 4, 2017
15375b9
Merge branch 'add-publisher-review' into adding-controller
springframeworkguru Oct 4, 2017
3769df7
Merge branch 'adding-controller' into adding-thymeleaf
springframeworkguru Oct 4, 2017
1559a08
Merge branch 'adding-thymeleaf' into display-authors
springframeworkguru Oct 4, 2017
474102a
Merge branch 'master' into jpa-entities
springframeworkguru Nov 10, 2017
6cc1801
Merge branch 'jpa-entities' into equals
springframeworkguru Nov 10, 2017
fea25c5
Merge branch 'equals' into spring-data-jpa
springframeworkguru Nov 10, 2017
3f577d9
Merge branch 'spring-data-jpa' into bootstrap
springframeworkguru Nov 10, 2017
83d11e7
Merge branch 'bootstrap' into add-publisher-review
springframeworkguru Nov 10, 2017
84b708a
Merge branch 'add-publisher-review' into adding-controller
springframeworkguru Nov 10, 2017
c10ae41
Merge branch 'adding-controller' into adding-thymeleaf
springframeworkguru Nov 10, 2017
f7acc99
Merge branch 'adding-thymeleaf' into display-authors
springframeworkguru Nov 10, 2017
63af265
Updated to 2.0.0.M7
springframeworkguru Dec 10, 2017
fd86699
Updated to Spring Boot 2.0.0.RELEASE
springframeworkguru Mar 17, 2018
cdbd54b
Upgraded to Spring Boot 2.1.0.RELEASE
springframeworkguru Dec 3, 2018
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M5</version>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package guru.springframework.spring5webapp.bootstrap;

import guru.springframework.spring5webapp.model.Author;
import guru.springframework.spring5webapp.model.Book;
import guru.springframework.spring5webapp.model.Publisher;
import guru.springframework.spring5webapp.repositories.AuthorRepository;
import guru.springframework.spring5webapp.repositories.BookRepository;
import guru.springframework.spring5webapp.repositories.PublisherRepository;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
* Created by jt on 5/16/17.
*/
@Component
public class DevBootstrap implements ApplicationListener<ContextRefreshedEvent> {

private AuthorRepository authorRepository;
private BookRepository bookRepository;
private PublisherRepository publisherRepository;

public DevBootstrap(AuthorRepository authorRepository, BookRepository bookRepository, PublisherRepository publisherRepository) {
this.authorRepository = authorRepository;
this.bookRepository = bookRepository;
this.publisherRepository = publisherRepository;
}

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
initData();
}

private void initData(){

Publisher publisher = new Publisher();
publisher.setName("foo");
publisher.setAddress("12th Street, LA");
publisherRepository.save(publisher);

//Eric
Author eric = new Author("Eric", "Evans");
Book ddd = new Book("Domain Driven Design", "1234", publisher);
eric.getBooks().add(ddd);
ddd.getAuthors().add(eric);

authorRepository.save(eric);
bookRepository.save(ddd);


//Rod
Author rod = new Author("Rod", "Johnson");
Book noEJB = new Book("J2EE Development without EJB", "23444", publisher );
rod.getBooks().add(noEJB);
noEJB.getAuthors().add(rod);

authorRepository.save(rod);
bookRepository.save(noEJB);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package guru.springframework.spring5webapp.controllers;

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

/**
* Created by jt on 5/18/17.
*/
@Controller
public class AuthorController {

private AuthorRepository authorRepository;

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

@RequestMapping("/authors")
public String getAuthors(Model model){

model.addAttribute("authors", authorRepository.findAll());

return "authors";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package guru.springframework.spring5webapp.controllers;

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

/**
* Created by jt on 5/18/17.
*/
@Controller
public class BookController {

private BookRepository bookRepository;

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

@RequestMapping("/books")
public String getBooks(Model model){

model.addAttribute("books", bookRepository.findAll());

return "books";
}
}
92 changes: 92 additions & 0 deletions src/main/java/guru/springframework/spring5webapp/model/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package guru.springframework.spring5webapp.model;

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

/**
* Created by jt on 5/16/17.
*/
@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(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public Author(String firstName, String lastName, Set<Book> books) {
this.firstName = firstName;
this.lastName = lastName;
this.books = books;
}

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 id != null ? id.equals(author.id) : author.id == null;
}

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

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

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

/**
* Created by jt on 5/16/17.
*/
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String isbn;

@OneToOne
private Publisher publisher;

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

public Book() {
}

public Book(String title, String isbn, Publisher publisher) {
this.title = title;
this.isbn = isbn;
this.publisher = publisher;
}

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

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 Publisher getPublisher() {
return publisher;
}

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

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

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

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

Book book = (Book) o;

return id != null ? id.equals(book.id) : book.id == null;
}

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

@Override
public String toString() {
return "Book{" +
"id=" + id +
", title='" + title + '\'' +
", isbn='" + isbn + '\'' +
", publisher='" + publisher + '\'' +
", authors=" + authors +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package guru.springframework.spring5webapp.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
* Created by jt on 5/17/17.
*/
@Entity
public class Publisher {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String address;

public Long getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

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

Publisher publisher = (Publisher) o;

return id != null ? id.equals(publisher.id) : publisher.id == null;
}

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

@Override
public String toString() {
return "Publisher{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
'}';
}
}
Loading