Generating Spring Boot CRUD Code with EasyCode Plugin in IntelliJ IDEA
This tutorial walks through installing the EasyCode and Lombok plugins, creating a MySQL table, configuring IDEA database connections, generating entity, DAO, service, controller, and mapper code for a Spring Boot project, and setting up the required Maven dependencies and application.yml configuration.
EasyCode is an IntelliJ IDEA plugin that can automatically generate entity, controller, service, DAO, and mapper code from database tables without manual coding, making development faster and more convenient.
1. Install EasyCode (and Lombok) – Add the EasyCode plugin in IDEA and also install Lombok to generate getters, setters, constructors, and other boilerplate methods at compile time.
2. Create the database table
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`username` varchar(20) DEFAULT NULL,
`sex` varchar(6) DEFAULT NULL,
`birthday` date DEFAULT NULL,
`address` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET FOREIGN_KEY_CHECKS = 1;3. Configure IDEA to connect to the database – After creating a Spring Boot project, open the Database tool window, add a new MySQL data source, and fill in the database name, username, and password.
4. Generate code with EasyCode – Right‑click the target table in the Database view, choose the EasyCode generation dialog, select the output folder, and tick the components you need (entity, DAO, service, controller, mapper). Click OK to generate the files.
5. Add required Maven dependencies (pom.xml)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>6. Configure application.yml
server:
port: 8089
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:/mapper/*Dao.xml
typeAliasesPackage: com.vue.demo.entity7. Adjust DAO and main application – Add @Mapper on DAO interfaces and @MapperScan("com.vue.demo.dao") on the Spring Boot main class.
8. Run the project – Start the Spring Boot application, then test the generated endpoints to verify that CRUD operations work as expected.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
