Generate Spring Boot CRUD Code Instantly with EasyCode Plugin
This guide walks through installing the EasyCode IntelliJ plugin, setting up a MySQL database, configuring a Spring Boot project, adding necessary Maven dependencies and application.yml settings, and using EasyCode to automatically generate CRUD code for the defined tables.
Overview
EasyCode is an IntelliJ IDEA plugin that generates Java code (entity, mapper, service, controller, etc.) from database tables using customizable templates. It maps database types to Java types and supports batch generation for multiple tables.
Prerequisites
IntelliJ IDEA (Community or Ultimate)
EasyCode plugin installed via Settings → Plugins → Marketplace
Lombok plugin (optional but recommended for reducing boilerplate)
Java 8+ and Maven
Database preparation
Create a MySQL database and the required tables. Example:
-- 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;Configure database connection in IDEA
In the Database tool window, add a new MySQL data source, fill in the URL, username, and password, and test the connection.
Generate code with EasyCode
Open the Spring Boot project in IDEA.
In the Database view, locate the target table, right‑click → EasyCode → Generate .
Select the output directory.
Check the components to generate (Entity, Mapper, Service, Controller, etc.).
Confirm – EasyCode creates the source files under the chosen package.
Maven dependencies
Add the following dependencies to pom.xml (adjust versions as needed):
<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>
<!-- Hot reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- MyBatis Spring Boot starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- MySQL driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- Alibaba Druid connection pool -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>application.yml configuration
server:
port: 8089
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
mybatis:
mapper-locations: classpath:/mapper/*Dao.xml
typeAliasesPackage: com.vue.demo.entityEnable MyBatis mapper scanning
Add @Mapper on each DAO interface and @MapperScan("com.vue.demo.dao") on the main Spring Boot application class.
Run the application
Execute mvn spring-boot:run or run the main method from the IDE. Verify that the generated REST endpoints are reachable (e.g., http://localhost:8089/user/list).
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
