Giter Club home page Giter Club logo

spring-boot-java-brains's Introduction

Spring Boot Quick Start ๐Ÿ”ฅ

This is a hands-on project from the Spring Boot Tutorial by Java Brains!

Development Process

With the development process of the Course Management System detailed below, I attempt to condense and provide some insight into what I have learnt throughout this course.

Initial Setup

  • Create a Maven project.
  • Add spring-boot-starter-web dependency.
  • Add CourseApiApp class and run the application.

Getting a List of Topics

  • Add Topic class with id, name, and description.
  • Add Topic RestController.
  • Add getAllTopics and its /topics RequestMapping.
  • Return a hardcoded list of Topic objects which Spring MVC converts to JSON.

Using a Business Service

  • Add TopicService class.
  • Inject or Autowire TopicService dependency into TopicController.
  • Refactor and move hardcoded list to TopicService.
  • Add getAllTopics service function.

Getting a Single Topic

  • Add getTopic service function.
  • Add /topics/{id} RequestMapping which calls service function with the PathVariable and returns the output.

Adding a Topic

  • Add POST RequestMethod mapping for /topics.
  • Pass theTopic instance from the RequestBody to the TopicService.
  • Add addTopic service function.

Updating and Deleting

  • Add PUT RequestMethod mapping for /topics/{id}.
  • Pass the RequestBody Topic instance and id PathVariable to TopicService.
  • Add updateTopic service function.
  • Add DELETE RequestMethod mapping for /topics/{id}.
  • Pass the id PathVariable to TopicService.
  • Add deleteTopic service function.

This is a good time to create an application.properties file and make any necessary configurations, such as changing the application port. It is good practice to frequently verify the state of the application and test endpoint changes using Postman.

Connecting to a Database

  • Add spring-boot-starter-data-jpa and derby embedded database dependencies to pom.xml.
  • Add Entity annotation to Topic class.
  • Add Id primary key annotation.
  • Add TopicRepository interface extending CrudRepository.
  • Autowire TopicRepository to TopicService.
  • Refactor TopicService to use built-in TopicRepository CRUD operation methods.

Adding Course API

  • Set up a Course package in the same way as the Topic package.
  • Establish a ManyToOne relationship from Course to Topic.
  • Add findByTopicId function declaration to CourseRepository interface.
  • Refactor CourseService to use functions provided by CourseRepository.
  • Refactor CourseController.
Course API
--------------
GET       /topics/{topicId}/courses          Get all courses
GET       /topics/{topicId}/courses/{id}     Get one course
POST      /topics/{topicId}/courses          Add new course
PUT       /topics/{topicId}/courses/{id}     Update a course
DELETE    /topics/{topicId}/courses/{id}     Delete a course

Add the spring-boot-starter-actuator and package the project as a jar or a traditional war. All good to go!

Thank you very much!

Open to any suggestions on how to make this better! Much appreciated!

spring-boot-java-brains's People

Contributors

mitulagr2 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.