How to Auto-Generate Spring Boot CRUD Code with EasyCode in IDEA
This guide walks you through installing the EasyCode plugin in IntelliJ IDEA, setting up a MySQL database, configuring Spring Boot dependencies, and using EasyCode to automatically generate entity, controller, service, DAO, and mapper classes, complete with Maven and application.yml settings.
EasyCode is an IntelliJ IDEA plugin that can generate entity, controller, service, DAO, and mapper classes directly from database tables without writing code.
1. Install EasyCode
After installing the plugin, it is recommended to also install Lombok, which generates constructors, getters/setters, equals, hashCode, and toString methods via annotations.
2. Create Database
-- ----------------------------
-- 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 Database Connection in IDEA
First create a Spring Boot project, then open the Database tool window, add a new data source, and fill in the database name, username, and password.
4. Generate Code
Right‑click the desired table in EasyCode, choose the output folder, and select the components to generate (entity, mapper, service, controller, etc.).
5. pom.xml Dependencies
<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 -->
<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>6. 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
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:/mapper/*.xml
typeAliasesPackage: com.vue.demo.entity7. Run the Project
Before starting, add @Mapper annotation to DAO interfaces and @MapperScan("com.vue.demo.dao") to the main application class, then launch the Spring Boot application and test the generated endpoints.
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.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
