Spring Boot - Quick Start
Spring Boot - Quick Start
Version: 3.0 - Date: 12.2021
About the Book
This is first Book in the series
Content
Intention of this Book is to quickly get you started using Spring Boot to develop Web Applications.
Book covers basic functionalities like: Controllers, Endpoints, Entities, DTOs, Services, Repositories.
Standalone Tutorials
The core of this Book are standalone tutorials that explain different functionalities of Spring Boot.
Each tutorial contains minimum amount of code needed to explain specific functionality.
And also minimum amount of encompassing text that explains related theory and different parts of the code.
This approach allows students to grasp presented concepts in a very fast and efficient manner.
Full code, which can also be downloaded from GitHub, prevents any time being wasted trying to make the code work.
Simple examples allow for full understanding of the functionality without any unnecessary distractions.
Theoretical Background
Where needed tutorials are preceded by chapters focusing on theoretical background.
This way reader can fully understand functionalities explained in the subsequent chapters.
But such chapters are in minority and of secondary importance because the main focus is on practical applications.
Demo Applications
Book contains demo Applications that show how to combine functionalities covered in previous tutorials. More complex Application "Authors & Books" is broken into multiple steps showing how to add additional functionalities at each step.
Bundles that include this book
Table of Contents
- 1. Quick Start
- 1.1 Install
- 1.1.1 Java
- 1.1.2 IntelliJ IDEA
- 1.2 Create Project with IntelliJ
- 1.2.1 Community Edition (free)
- 1.2.2 Ultimate Edition (paid)
- 1.3 Other
- 1.3.1 Run Application
- 1.3.2 Create Spring Boot Web Application
- 1.3.3 Clone Project from GitHub Repository
- 2. Terms
- 2.1 Project
- 2.1.1 Spring Initializer
- 2.1.2 Spring Boot Starters
- 2.1.3 Spring Boot Project
- 2.2 Types of Java Classes
- 2.2.1 Controller
- 2.2.2 Service
- 2.2.3 Repository
- 2.2.4 Entity
- 2.2.5 DTO
- 3. Basic Functionality
- 3.1 Profiles
- 3.1.1 Assign Profile - To Class
- 3.1.2 Assign Profile - To application.properties
- 3.2 application.properties
- 3.2.1 Read Property - From Controller
- 3.2.2 Read Property - From HTML
- 3.3 @Autowired
- 3.3.1 Manually
- 3.3.2 Inject into - Property
- 3.3.3 Inject into - Setter Parameter
- 3.3.4 Inject into - Constructor Parameter
- 3.3.5 Interface - @Primary
- 3.3.6 Interface - @Qualifier
- 3.3.7 Interface - @Profile
- 3.4 Service
- 3.4.1 Business Logic - Inside Controller
- 3.4.2 Business Logic - Inside Service
- 3.4.3 Instantiate Service - Using Class
- 3.4.4 Instantiate Service - Using Class - @Autowired
- 3.4.5 Instantiate Service - Using Interface
- 3.4.6 Instantiate Service - Using Interface - @Autowired
- 4. Controller
- 4.1 Annotations
- 4.1.1 @Controller
- 4.1.2 @RestController
- 4.1.3 @RequestMapping
- 4.2 Endpoints
- 4.2.1 HTTP Method - @RequestMapping
- 4.2.2 HTTP Method - @GetMapping
- 4.2.3 HTTP Method - @PostMapping
- 4.2.4 HTTP Parameters - @RequestParam
- 4.2.5 HTTP Parameters - @PathVariable
- 4.2.6 Return - Data - Text
- 4.2.7 Return - View - HTML
- 4.2.8 Return - View - Thymeleaf
- 4.2.9 Return - View - JSP
- 4.2.10 Download - Excel
- 4.2.11 Download - Excel - With Header
- 4.3 Load Request Parameters into DTO
- 4.3.1 Using DTO Setters
- 4.3.2 Using DTO Setters - Custom
- 4.3.3 Using Map
- 4.3.4 Using Map & ObjectMapper - DTO Properties
- 4.3.5 Using Map & ObjectMapper - DTO Setters
- 4.3.6 Using Map & ObjectMapper - DTO Setters - Custom
- 4.4 Read HTML Form Fields
- 4.4.1 Into @RequestParam - Using Postman
- 4.4.2 Into @RequestParam - Using HTML Page
- 4.4.3 Into PersonDTO - Using Postman
- 4.4.4 Into PersonDTO - Using HTML Page
- 5. JSON
- 5.1 Deserialize
- 5.1.1 Properties
- 5.1.2 Setters
- 5.1.3 Setters - Custom
- 5.1.4 Constructor
- 5.1.5 Constructor - Custom
- 5.1.6 Order of use
- 5.1.7 JSON Array
- 5.1.8 JSON Array - Children
- 5.1.9 @JsonProperty - Properties
- 5.1.10 @JsonProperty - Setters
- 5.1.11 @JsonProperty - Constructor
- 5.1.12 @JsonFormat - Properties
- 5.1.13 @JsonFormat - Setters
- 5.1.14 @JsonFormat - Constructor
- 5.1.15 @JsonDeserialize
- 5.2 Serialize
- 5.2.1 Properties
- 5.2.2 Getters
- 5.2.3 Getters - Custom
- 5.2.4 @JsonProperty - Properties
- 5.2.5 @JsonProperty - Getters
- 5.2.6 @JsonFormat - Properties
- 5.2.7 @JsonFormat - Getters
- 5.2.8 @JsonSerialize
- 6. XML
- 6.1 Deserialize
- 6.1.1 Properties
- 6.1.2 Setters
- 6.1.3 Annotations - Properties
- 6.1.4 Annotations - Setters
- 6.2 Serialize
- 6.2.1 Properties
- 6.2.2 Getters
- 6.2.3 Annotations - Properties
- 6.2.4 Annotations - Getters
- 7. Object Mapping
- 7.1 Manual Mapping
- 7.2 JMapper
- 7.2.1 Example
- 7.3 Map Struct
- 7.3.1 Example
- 7.4 Model Mapper
- 7.4.1 Default Mapping
- 7.4.2 Custom Mapping
- 7.4.3 Exclude Mapping
- 8. Database
- 8.1 Entity
- 8.1.1 Properties - Public
- 8.1.2 Properties - Private - Getters & Setters
- 8.1.3 Properties - Private - Getters & Constructor
- 8.1.4 @Entity
- 8.1.5 @Id
- 8.1.6 @IdClass
- 8.1.7 @EmbeddedId
- 8.1.8 @Table
- 8.1.9 @Column
- 8.1.10 @Transient
- 8.1.11 @CreationTimestamp, @UpdateTimestamp
- 8.1.12 PostgreSQL - jsonb
- 8.1.13 PostgreSQL - Store byte[] - OID
- 8.1.14 PostgreSQL - Store byte[] - bytea
- 8.2 Connectors
- 8.2.1 H2
- 8.2.2 MySQL
- 8.2.3 PostgreSQL
- 8.2.4 MongoDB
- 8.3 Relationships
- 8.3.1 @OneToOne - Join Table
- 8.3.2 @OneToOne - Foreign Key
- 8.3.3 @OneToMany - Join Table
- 8.3.4 @OneToMany - Foreign Key
- 8.3.5 @ManyToMany - Join Table
- 8.3.6 Eager vs Lazy
- 9. Demo Applications
- 9.1 Simple Applications
- 9.1.1 Store Entity from JSON
- 9.1.2 Store Entities from JSON Array
- 9.2 Authors & Books
- 9.2.1 Step 1: Create Project
- 9.2.2 Step 2: Entity - Author
- 9.2.3 Step 3: Entity - Book
- 9.2.4 Step 4: Relationship @OneToMany
- 9.2.5 Step 5: Service - Add Author
- 9.2.6 Step 6: Service - Add Book
- 9.2.7 Step 7: Service - Get Books
- 9.2.8 Step 8: Service - Add Author & Book
- 10 Appendix
- 10.1 Lombok
- 10.1.1 Lombok API - Use
- 10.1.2 Lombok Plugin - Install for IntelliJ
- 10.1.3 Lombok Plugin - Lombok
- 10.1.4 Lombok Plugin - Delombok
- 10.2 IntelliJ
- 10.2.1 Copy Project
- 10.2.2 DB Tools
- 10.3 IntelliJ - JAR
- 10.3.1 Create JAR - Using Artifact
- 10.3.2 Create JAR - Using Maven - Targets
- 10.3.3 Create JAR - Using Maven - Configuration
- 10.3.4 Execute JAR - Using IntelliJ
- 10.3.5 Execute JAR - Using Command Prompt
- 10.4 IntelliJ - Automatically reload Application
- 10.4.1 Install Chrome Extension: Live Reload
- 10.4.2 IntelliJ Registry: compiler.automake
- 10.4.3 Run Configuration: Update classes and resources
- 10.4.4 Settings: Build Project Automatically
- 10.4.5 Create Spring Boot Project
- 10.5 Database - H2
- 10.5.1 Application Example
- 10.5.2 DB: Specify Name
- 10.5.3 Console: Enable
- 10.5.4 Console: Open
- 10.5.5 Console: Show Records
- 10.5.6 Console: Security
- 10.6 Database - MySQL
- 10.6.1 Create Schema/Database
- 10.6.2 Create User
- 10.6.3 Add Privileges to User
- 10.7 Database - PosgreSQL
- 10.7.1 Create Database
- 10.7.2 Create User
- 11 Errors
- 11.1 Maven
- 11.1.1 Plugin 'spring-boot-maven-plugin:' not found
- 11.2 Controller
- 11.2.1 Circular view path
- 11.2.2 No qualifying bean of type available
- 11.2.3 Could not find acceptable representation
- 11.2.4 Unrecognized field
- 11.2.5 Cannot deserialize value of type `java.time.LocalDate`
- 11.2.6 Endpoint doesn't return JSON
- 11.3 Database
- 11.3.1 Cannot Resolve Table
- 11.3.2 Records are not inserted into DB
- 11.3.3 Database Tool Window can't see H2 Tables
- 11.3.4 Driver org.postgresql.Driver claims to not accept jdbcUrl
- 11.3.5 ids for this class must be manually assigned
- 11.3.6 @OneToOne or @ManyToOne references an unknown entity
- 11.3.7 object references an unsaved transient instance
- 11.3.8 Table [book] contains logical column name
- 11.3.9 nested exception is javax.persistence.TransactionRequiredException
- 11.3.10 query did not return a unique result: 2
- 11.3.11 Column name was not found in ResultSet
- 11.4 Mappers
- 11.4.1 Map Struct: Cannot resolve symbol 'Mappers'
- 11.4.2 Map Struct: No property named "authorAge" exists in source parameter(s)
- 11.4.3 Map Struct: Unknown property "age" in result type
- 11.4.4 Map Struct: Cannot find implementation for MyMapper
- 11.4.5 Model Mapper: Not mapping
- 11.4.6 Model Mapper: NullPointerException
- 11.5 Other
- 11.5.1 Not a managed type
- 11.5.2 @Value doesn't load application property
- 11.5.3 UnsupportedClassVersionError
- 11.5.4 Registry key has value '1.8', but '1.7' is required
- 12 Summary
- 12.1 Application
- 12.1.1 Create & Run
- 12.1.2 Deploy
- 12.1.3 Objects
- 12.2 Basic Functionality
- 12.2.1 application.properties
- 12.2.2 Profiles
- 12.2.3 @Autowired
- 12.2.4 Service
- 12.3 Controller & Endpoints
- 12.3.1 Controller
- 12.3.2 URL Mapping
- 12.3.3 Endpoint - Input Parameters
- 12.3.4 Endpoint - Return Data
- 12.3.5 Endpoint - Return Web Page
- 12.4 Read All Request Parameters
- 12.4.1 Using Setters
- 12.4.2 Using Map
- 12.4.3 Using Map & ObjectMapper
- 12.5 JSON
- 12.5.1 Deserialize/Serialize single Object
- 12.5.2 Deserialize JSON Array
- 12.5.3 @JsonDeserialize
- 12.5.4 @JsonSerialize
- 12.6 XML
- 12.6.1 Serialize/Deserialize single Object
- 12.7 Object Mapping
- 12.7.1 JMapper
- 12.7.2 Model Mapper
- 12.7.3 Map Struct
- 12.8 Databases
- 12.8.1 Connections
- 12.8.2 Entity
- 12.8.3 Relationships
- 13 Syntax Summary
- 13.1 Application
- 13.2 Basic Functionality
- 13.3 Controller & Endpoints
- 13.3.1 Read Input Parameters
- 13.3.2 Read All Request Parameters
- 13.3.3 Return Data
- 13.3.4 Return Web page
- 13.4 Deserialize/Serialize
- 13.4.1 JSON
- 13.4.2 XML
- 13.5 Object Mapping
- 13.6 Database
- 13.6.1 Relationships
- 14 Practice
- 14.1 Tasks
- 14.2 Answers
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,712,765writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Recipes for Decoupling
Matthias NobackWrite software that survives
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
CQRS by Example
Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary- Leverage your Software Architecture skills by learning everything about CQRS in detail with lots of examples
- Develop faster applications by applying CQRS and fostering Read Models and Projections
- Learn how to apply CQRS into a brownfield project from a pragmatic approach
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
The PowerShell Scripting and Toolmaking Book
Don Jones and Jeff HicksLearn the patterns, practices, and details of PowerShell Scripting and Toolmaking from the industry's two most recognized experts on the subject.
The C4 model for visualising software architecture
Simon BrownA guide to visualising your software architecture with the C4 model.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #6
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #8
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming...