Instantly Generate Spring Boot CRUD Code with EasyCode Plugin
This tutorial walks you through installing the EasyCode IntelliJ plugin, setting up a MySQL database, configuring a Spring Boot project, adding necessary Maven dependencies and YAML settings, and using EasyCode to automatically generate entity, DAO, service, controller, and mapper code without manual coding.
1. Install EasyCode plugin
Install the EasyCode plugin in IntelliJ IDEA; it can generate entity, controller, service, DAO, and mapper classes directly from database tables without writing any code.
It is also recommended to install Lombok, which creates constructors, getters, setters, equals, hashCode, and toString methods at compile time 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
Create a Spring Boot project, then open the Database tool window in IDEA and add a new MySQL connection using the database name, username, and password.
4. Generate code
In the project, locate the table you want to generate code for, right‑click and choose the EasyCode generation option. Select the target folder for the generated files and click OK.
5. Add dependencies to 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>
<!-- 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. 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. Start the project
Before running, add @Mapper annotation to DAO interfaces and @MapperScan("com.vue.demo.dao") to the main Spring Boot application class.
Run 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.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
