POJO Generator: Support creating Pojos automatically in Intellij Idea
Hello everyone, in previous posts, I have introduced to you a library called Lombok. This library helps us to simplify the creation of POJOs (Plain Old Java Objects) in Java.
But in fact, in many projects, we want to be able to generate Entity, DTO classes from the tables in the database because the number of tables and fields in is a lot.
If you create it manually, it will be very time consuming and also very error prone. At this point you should install POJO Generator (a great plugin for IntelliJ Idea users).
#first. Connect to the database
First, you have to connect to the database you use through IntelliJ first. Specifically, how to connect data, I already have a separate tutorial article.
You can refer here: How to connect MySQL Server in IntelliJ, it's time to quit MySQL Workbench
In this article, I will connect to the MySQL database management system as shown below. You can choose any database management system you like.
Fill in the connection information (you can refer to the article above for more details) => then click Apply to connect to the database.
This is the database I connected to. You can click on the Database tab as shown below to open it.
#2. Install POJO Generator Plugin
The next step is that we will install the POJO Generator utility to be able to automatically generate Entities and DTO classes during Java code.
You go to File => Settings as shown below.
In the Plugins tab, select Marketplace as shown below => Then enter POJO Generator in the search box and click search.
Search results, you select the plugin as shown below => then click Install to install. Finally click OK to confirm and if possible Restart IntelliJ to activate this utility.
#3. Generate Entity classes, DTOs based on the database table
After installing the plugin, you reopen the Database tab that you just connected in Step 1. Here you want to generate Entity class or DTO class from any table, right-click on that table.
At the bottom there will be an option to use POJO Generator. You can click and choose to generate Entities as well as DTOs corresponding to that table.
After choosing to generate Entity or DTO, you must choose the folder you will contain the class after it is generated. Here I usually put it in the model folder of the project. You can put it in any folder in the project.
After clicking OK, this is the Entity class that the utility has automatically generated for you. The fields in the database will be mapped corresponding to the fields in the generated class.
To generate a DTO class, you also do the same as with Entity class.
You can create a separate folder called dto to store DTO (Data Transfer Object) classes.
And this is the content of the generated DTO file corresponding to the customers table in the database.
As you can see, in fact, this plugin still generates setter and getter functions (making Entity and DTO classes untidy and time consuming to compile into .class files)
To overcome this drawback, you can delete all the Setter, Getter functions and with the Lombok library as follows.
Okay, so I've finished showing you how to install POJO Generator on IntelliJ to automatically generate Entity and DTO classes based on tables in the database.
With real projects, it is very important for programmers to have more time to focus on solving business-related problems, with the time saved, the programmer will have the opportunity improve the quality of the source code for the project to be better.
Yes, and extensions/plugins like POJO Generator, Lombok library… were born with just that purpose. Helps to minimize the programmer's time spent on procedural operations.
Hopefully this article will help Java programmers have more tools to optimize their programming time. See you in the next posts
You should read it
- 4 best QR code generator tools for PDF
- Generator in Python
- Should you use a password generator to protect your online accounts?
- Instructions on how to connect to MySQL Server in IntelliJ
- How to generate QR codes with Me QR Generator on phones and computers
- How to use AI Background Generator to create images based on keywords
- self-maintenance steps, generator maintenance
- Instructions for using Chrome's built-in password generator
May be interested
- How to use AI Background Generator to create images based on keywordsai background generator creates images using keywords about a photo in your imagination and the results will surprise us.
- self-maintenance steps, generator maintenancetip you the process of self-maintenance, maintenance of home generator through the article below, follow along!
- Create super funny photo effects on Windows 10 with Meme Generator Suite applicationmeme generator suite is a special application for creating hot photos, meme generator suite has a multitude of unique and funny models to help you create unique images even though not a photo editor. profession. just follow the instructions in the article below that you can own a beautiful image equally with the appearing photos flooded on social networks.
- Instructions on how to create QR codes on Android with QR Code Generatorin the previous article, tipsmake.com showed you how to create qr codes on iphone. today, let's see how to create qr codes on android devices with the qr code generator app!
- Instructions to turn off the creation of the Facebook security code on the phonemany people think that turning off code generator can be done on the phone. however, you still have to do this on your computer. here, we will guide you how to turn off the code generator security code generator on the facebook application for your phone:
- How to use the Smart Lock password generator for Chromechrome has many hidden and unknown features that are extremely useful. one of them is an integrated password generator, used to create strong passwords when creating new accounts and a password management tool called smart lock that helps store those passwords on google.com to get back when need.
- How to Automatically Have Wallpaper Change on Ubuntudo you like the idea of a wallpaper that changes automatically? if you're looking for that kind of variety, you can set your desktop wallpaper to change automatically at certain intervals in ubuntu using wallch. open the terminal. first...
- 5 websites create the most powerful random passwordtoday, a strong password is essential on the web. fortunately, you can use the online password generator, which helps create strong and unique passwords for your account.
- Steps to install and setup Android Studio in Windowsandroid studio is the official ide (integrated development environment) for android application development and it is based on jetbrains 'intellij idea software. android studio offers many great features that enhance productivity when building android apps.
- How to read QR codes on computersqr codes are becoming increasingly popular and widely used. you can easily find them on banners, product boxes, web pages or even email signatures. the question is how to decode a qr code icon? very simple, today tipsmake.com will introduce you how to read qr codes on your computer with codetwo qr code desktop reader & generator application.