diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
new file mode 100644
index 0000000000..22810754a3
--- /dev/null
+++ b/.mvn/wrapper/MavenWrapperDownloader.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.net.*;
+import java.io.*;
+import java.nio.channels.*;
+import java.util.Properties;
+
+public class MavenWrapperDownloader {
+
+ private static final String WRAPPER_VERSION = "0.5.5";
+ /**
+ * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
+ */
+ private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
+
+ /**
+ * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
+ * use instead of the default one.
+ */
+ private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
+ ".mvn/wrapper/maven-wrapper.properties";
+
+ /**
+ * Path where the maven-wrapper.jar will be saved to.
+ */
+ private static final String MAVEN_WRAPPER_JAR_PATH =
+ ".mvn/wrapper/maven-wrapper.jar";
+
+ /**
+ * Name of the property which should be used to override the default download url for the wrapper.
+ */
+ private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
+
+ public static void main(String args[]) {
+ System.out.println("- Downloader started");
+ File baseDirectory = new File(args[0]);
+ System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
+
+ // If the maven-wrapper.properties exists, read it and check if it contains a custom
+ // wrapperUrl parameter.
+ File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
+ String url = DEFAULT_DOWNLOAD_URL;
+ if(mavenWrapperPropertyFile.exists()) {
+ FileInputStream mavenWrapperPropertyFileInputStream = null;
+ try {
+ mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
+ Properties mavenWrapperProperties = new Properties();
+ mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
+ url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
+ } catch (IOException e) {
+ System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
+ } finally {
+ try {
+ if(mavenWrapperPropertyFileInputStream != null) {
+ mavenWrapperPropertyFileInputStream.close();
+ }
+ } catch (IOException e) {
+ // Ignore ...
+ }
+ }
+ }
+ System.out.println("- Downloading from: " + url);
+
+ File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
+ if(!outputFile.getParentFile().exists()) {
+ if(!outputFile.getParentFile().mkdirs()) {
+ System.out.println(
+ "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
+ }
+ }
+ System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
+ try {
+ downloadFileFromURL(url, outputFile);
+ System.out.println("Done");
+ System.exit(0);
+ } catch (Throwable e) {
+ System.out.println("- Error downloading");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ private static void downloadFileFromURL(String urlString, File destination) throws Exception {
+ if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
+ String username = System.getenv("MVNW_USERNAME");
+ char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(username, password);
+ }
+ });
+ }
+ URL website = new URL(urlString);
+ ReadableByteChannel rbc;
+ rbc = Channels.newChannel(website.openStream());
+ FileOutputStream fos = new FileOutputStream(destination);
+ fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+ fos.close();
+ rbc.close();
+ }
+
+}
diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar
index 9cc84ea9b4..0d5e649888 100644
Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index c315043703..7d59a01f25 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1 +1,2 @@
-distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
diff --git a/mvnw b/mvnw
index 5bf251c077..21d3ee8456 100755
--- a/mvnw
+++ b/mvnw
@@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
@@ -108,13 +108,12 @@ if $cygwin ; then
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
-# For Migwn, ensure paths are in UNIX format before anything is touched
+# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
- # TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
@@ -200,8 +199,89 @@ if [ -z "$BASE_DIR" ]; then
exit 1;
fi
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found .mvn/wrapper/maven-wrapper.jar"
+ fi
+else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ fi
+ if [ -n "$MVNW_REPOURL" ]; then
+ jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+ else
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+ fi
+ while IFS="=" read key value; do
+ case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ esac
+ done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Downloading from: $jarUrl"
+ fi
+ wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+ if $cygwin; then
+ wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
+ fi
+
+ if command -v wget > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found wget ... using wget"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ wget "$jarUrl" -O "$wrapperJarPath"
+ else
+ wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
+ fi
+ elif command -v curl > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found curl ... using curl"
+ fi
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ curl -o "$wrapperJarPath" "$jarUrl" -f
+ else
+ curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+ fi
+
+ else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Falling back to using Java to download"
+ fi
+ javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ # For Cygwin, switch paths to Windows format before running javac
+ if $cygwin; then
+ javaClass=`cygpath --path --windows "$javaClass"`
+ fi
+ if [ -e "$javaClass" ]; then
+ if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Compiling MavenWrapperDownloader.java ..."
+ fi
+ # Compiling the Java class
+ ("$JAVA_HOME/bin/javac" "$javaClass")
+ fi
+ if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ # Running the downloader
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Running MavenWrapperDownloader.java ..."
+ fi
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ fi
+ fi
+ fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
-echo $MAVEN_PROJECTBASEDIR
+if [ "$MVNW_VERBOSE" = true ]; then
+ echo $MAVEN_PROJECTBASEDIR
+fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
@@ -216,6 +296,11 @@ if $cygwin; then
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
diff --git a/mvnw.cmd b/mvnw.cmd
index 019bd74d76..84d60abc33 100644
--- a/mvnw.cmd
+++ b/mvnw.cmd
@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
-@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@@ -35,7 +35,9 @@
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
-@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@REM set title of command window
+title %0
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
@@ -115,10 +117,47 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
-
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+
+FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Found %WRAPPER_JAR%
+ )
+) else (
+ if not "%MVNW_REPOURL%" == "" (
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+ )
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+ )
+
+ powershell -Command "&{"^
+ "$webclient = new-object System.Net.WebClient;"^
+ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+ "}"^
+ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
+ "}"
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Finished downloading %WRAPPER_JAR%
+ )
+)
+@REM End of extension
+
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
diff --git a/pom.xml b/pom.xml
index f34c1936df..bf90398e89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,47 +1,39 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.2.RELEASE
+
+
guru.springframework
spring5webapp
0.0.1-SNAPSHOT
- jar
spring5webapp
- Demo project for Spring Boot
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.1.2.RELEASE
-
-
+ Example Spring 5 Web Application
- UTF-8
- UTF-8
- 1.8
+ 11
-
- org.springframework.boot
- spring-boot-starter-actuator
-
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
- spring-boot-starter-thymeleaf
+ spring-boot-starter-web
org.springframework.boot
- spring-boot-starter-web
+ spring-boot-starter-thymeleaf
-
com.h2database
h2
@@ -51,6 +43,12 @@
org.springframework.boot
spring-boot-starter-test
test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
@@ -63,43 +61,4 @@
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
-
-
diff --git a/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java b/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java
new file mode 100644
index 0000000000..a4f162af88
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java
@@ -0,0 +1,67 @@
+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 {
+
+ private final AuthorRepository authorRepository;
+ private final BookRepository bookRepository;
+ private final PublisherRepository publisherRepository;
+
+ public BootStrapData(AuthorRepository authorRepository, BookRepository bookRepository, PublisherRepository publisherRepository) {
+ this.authorRepository = authorRepository;
+ this.bookRepository = bookRepository;
+ this.publisherRepository = publisherRepository;
+ }
+
+ @Override
+ public void run(String... args) throws Exception {
+
+ System.out.println("Started in Bootstrap");
+
+ Publisher publisher = new Publisher();
+ publisher.setName("SFG Publishing");
+ publisher.setCity("St Petersburg");
+ publisher.setState("FL");
+
+ publisherRepository.save(publisher);
+
+ System.out.println("Publisher Count: " + publisherRepository.count());
+
+ Author eric = new Author("Eric", "Evans");
+ Book ddd = new Book("Domain Driven Design","123123");
+ eric.getBooks().add(ddd);
+ ddd.getAuthors().add(eric);
+
+ ddd.setPublisher(publisher);
+ publisher.getBooks().add(ddd);
+
+ authorRepository.save(eric);
+ bookRepository.save(ddd);
+ publisherRepository.save(publisher);
+
+ Author rod = new Author("Rod", "Johnson");
+ Book j2ee = new Book("J2EE Development without EJB","395454589");
+ rod.getBooks().add(j2ee);
+ j2ee.getAuthors().add(rod);
+
+ j2ee.setPublisher(publisher);
+ publisher.getBooks().add(j2ee);
+
+ authorRepository.save(rod);
+ bookRepository.save(j2ee);
+ publisherRepository.save(publisher);
+
+ System.out.println("NUmber of books: "+ bookRepository.count());
+ System.out.println("Publisher Number of books: "+ publisher.getBooks().size());
+
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/controller/AuthorController.java b/src/main/java/guru/springframework/spring5webapp/controller/AuthorController.java
new file mode 100644
index 0000000000..2096f78565
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/controller/AuthorController.java
@@ -0,0 +1,23 @@
+package guru.springframework.spring5webapp.controller;
+
+import guru.springframework.spring5webapp.repositories.AuthorRepository;
+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 getAuthors(Model model){
+ model.addAttribute("authors", authorRepository.findAll());
+
+ return "authors/list";
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/controller/BookController.java b/src/main/java/guru/springframework/spring5webapp/controller/BookController.java
new file mode 100644
index 0000000000..ee3353752c
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/controller/BookController.java
@@ -0,0 +1,26 @@
+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;
+
+/**
+ * Created by jt on 12/24/19.
+ */
+@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";
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Author.java b/src/main/java/guru/springframework/spring5webapp/domain/Author.java
new file mode 100644
index 0000000000..2bab649bdd
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/domain/Author.java
@@ -0,0 +1,82 @@
+package guru.springframework.spring5webapp.domain;
+
+import javax.persistence.*;
+import java.util.HashSet;
+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 books = new HashSet<>();
+
+ public Author() {
+ }
+
+ public Author(String firstName, String lastName) {
+ 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 getBooks() {
+ return books;
+ }
+
+ public void setBooks(Set books) {
+ this.books = books;
+ }
+
+ @Override
+ public String toString() {
+ return "Author{" +
+ "id=" + id +
+ ", firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ '}';
+ }
+
+ @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;
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Book.java b/src/main/java/guru/springframework/spring5webapp/domain/Book.java
new file mode 100644
index 0000000000..8c25d381b3
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/domain/Book.java
@@ -0,0 +1,96 @@
+package guru.springframework.spring5webapp.domain;
+
+import javax.persistence.*;
+import java.util.HashSet;
+import java.util.Set;
+
+@Entity
+public class Book {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ private String title;
+ private String isbn;
+
+ @ManyToOne
+ private Publisher publisher;
+
+ @ManyToMany
+ @JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "book_id"),
+ inverseJoinColumns = @JoinColumn(name = "author_id"))
+ private Set authors = new HashSet<>();
+
+ public Book() {
+ }
+
+ public Book(String title, String isbn) {
+ this.title = title;
+ this.isbn = isbn;
+ }
+
+ public Publisher getPublisher() {
+ return publisher;
+ }
+
+ public void setPublisher(Publisher publisher) {
+ 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 getAuthors() {
+ return authors;
+ }
+
+ public void setAuthors(Set authors) {
+ this.authors = authors;
+ }
+
+ @Override
+ public String toString() {
+ return "Book{" +
+ "id=" + id +
+ ", title='" + title + '\'' +
+ ", isbn='" + isbn + '\'' +
+ '}';
+ }
+
+ @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;
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Publisher.java b/src/main/java/guru/springframework/spring5webapp/domain/Publisher.java
new file mode 100644
index 0000000000..69fdae8015
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/domain/Publisher.java
@@ -0,0 +1,109 @@
+package guru.springframework.spring5webapp.domain;
+
+import javax.persistence.*;
+import java.util.HashSet;
+import java.util.Set;
+
+@Entity
+public class Publisher {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ private String name;
+ private String addressLine1;
+ private String city;
+ private String state;
+ private String zip;
+
+ @OneToMany
+ @JoinColumn(name = "publisher_id")
+ private Set books = new HashSet<>();
+
+ public Publisher() {
+ }
+
+ public Set getBooks() {
+ return books;
+ }
+
+ public void setBooks(Set books) {
+ this.books = books;
+ }
+
+ @Override
+ public String toString() {
+ return "Publisher{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", addressLine1='" + addressLine1 + '\'' +
+ ", city='" + city + '\'' +
+ ", state='" + state + '\'' +
+ ", zip='" + zip + '\'' +
+ '}';
+ }
+
+ @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;
+ }
+
+ 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 getAddressLine1() {
+ return addressLine1;
+ }
+
+ public void setAddressLine1(String addressLine1) {
+ this.addressLine1 = addressLine1;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java b/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java
new file mode 100644
index 0000000000..a5aa1f8726
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java
@@ -0,0 +1,7 @@
+package guru.springframework.spring5webapp.repositories;
+
+import guru.springframework.spring5webapp.domain.Author;
+import org.springframework.data.repository.CrudRepository;
+
+public interface AuthorRepository extends CrudRepository {
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java b/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java
new file mode 100644
index 0000000000..570726803e
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java
@@ -0,0 +1,7 @@
+package guru.springframework.spring5webapp.repositories;
+
+import guru.springframework.spring5webapp.domain.Book;
+import org.springframework.data.repository.CrudRepository;
+
+public interface BookRepository extends CrudRepository {
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/repositories/PublisherRepository.java b/src/main/java/guru/springframework/spring5webapp/repositories/PublisherRepository.java
new file mode 100644
index 0000000000..8445629922
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/repositories/PublisherRepository.java
@@ -0,0 +1,7 @@
+package guru.springframework.spring5webapp.repositories;
+
+import guru.springframework.spring5webapp.domain.Publisher;
+import org.springframework.data.repository.CrudRepository;
+
+public interface PublisherRepository extends CrudRepository {
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index e69de29bb2..0611e04b46 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+spring.h2.console.enabled=true
+
diff --git a/src/main/resources/templates/authors/list.html b/src/main/resources/templates/authors/list.html
new file mode 100644
index 0000000000..f554f14b42
--- /dev/null
+++ b/src/main/resources/templates/authors/list.html
@@ -0,0 +1,24 @@
+
+
+
+
+ Spring Framework Guru
+
+
+Book List
+
+
+
+ ID |
+ Name |
+ Surname |
+
+
+ N# |
+ name |
+ surname |
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/books/list.html b/src/main/resources/templates/books/list.html
new file mode 100644
index 0000000000..748b6c2b0b
--- /dev/null
+++ b/src/main/resources/templates/books/list.html
@@ -0,0 +1,24 @@
+
+
+
+
+ Spring Framework Guru
+
+
+Book List
+
+
+
+ ID |
+ Title |
+ Publisher |
+
+
+ 123 |
+ Spring in Action |
+ Wrox |
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/guru/springframework/spring5webapp/Spring5webappApplicationTests.java b/src/test/java/guru/springframework/spring5webapp/Spring5webappApplicationTests.java
index e78ac1b703..5199fda6a6 100644
--- a/src/test/java/guru/springframework/spring5webapp/Spring5webappApplicationTests.java
+++ b/src/test/java/guru/springframework/spring5webapp/Spring5webappApplicationTests.java
@@ -1,16 +1,8 @@
package guru.springframework.spring5webapp;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
+class Spring5webappApplicationTests {
-@RunWith(SpringRunner.class)
-@SpringBootTest
-public class Spring5webappApplicationTests {
-
- @Test
- public void contextLoads() {
+ void contextLoads() {
}
}