Using EasyCode Plugin in IntelliJ IDEA to Auto‑Generate Spring Boot CRUD Code
This tutorial explains how to install the EasyCode plugin, set up a MySQL database, configure IDEA, generate entity, controller, service, DAO, and mapper code for a Spring Boot project, and adjust Maven and YAML settings to run the application successfully.
EasyCode is an IntelliJ IDEA plugin that can generate entity, controller, service, DAO, and mapper classes directly from database tables without writing any code, making development simple and powerful.
1. Install EasyCode – Install the EasyCode plugin in IDEA (the author also recommends installing Lombok to automatically generate getters, setters, constructors, etc.).
2. Create the database – Define the user table in MySQL:
-- ----------------------------
-- 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 – Create a new Spring Boot project, open the Database tool window, add a new MySQL connection, and fill in the database name, username, and password.
4. Generate code – In the Project view, right‑click the target table, choose the EasyCode generation option, select the output folder, and check the components (entity, mapper, service, controller, etc.) you want to generate.
5. Add required 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‑deployment -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</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 for the data source and MyBatis:
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 – Add @MapperScan("com.vue.demo.dao") to the main application class, ensure DAO interfaces are annotated with @Mapper, then run the Spring Boot application and test the generated endpoints.
The tutorial concludes by encouraging readers to try EasyCode for rapid code generation.
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.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
