Загрузка...

Spring Boot - MongoDB Tutorial | beginners |

SpringBoot Tutorial with MongoDB for beginners. Let’s create a car rental web service: 1. Go to https://start.spring.io/ to generate your carrental SpringBoot project 2. Set project configuration : * Choose Maven Project * Give it a name (Artifact) * Add Spring Web as dependencies (library) * Add DevTools as dependencies * Add spring data mongoDB as dependencies * Generate the project 3. Download and unzip the project 4. Open the project 5. Create your model class Car with these attributes : - String plateNumber; - String brand; - int price; - Add annotations (@Id, @Document) - Create getters and setters - Create constuctor 6. Create CarRepository interface. 7. Create CarRentalService class with will contains endpoints : - GET - /cars - getListOfCars() - POST - /cars - addCar() - GET - /cars/plateNumber - getCar() 8. Run a MongoDB docker image and map it to your local port : - docker run -d -p 27017-27019:27017-27019 --name mongodb-carrental mongo:4.0.4 9. Run your application class. 10. Test your endpoints with Postman You can check MongoDB database with these following commands : - docker exec -it mongodb-carrental bash - mongo - show dbs You can stop your MongoDB docker container and remove it with these commands : - docker stop mongodb-carrental - docker rm mongodb-carrental

Видео Spring Boot - MongoDB Tutorial | beginners | автора Создание чат-ботов: основы и практика для всех
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки