Home > Java > javaTutorial > body text

EasyCode: Generate code with one click

Release: 2023-07-26 17:17:20
forward
3765 people have browsed it

Easycode is a plug-in of idea, which can directly generate entities, controllers, services, dao, and mappers for data tables without any coding. It is simple and powerful.

1. Installation (EasyCode)

EasyCode: Generate code with one click

I have already installed it here.

It is recommended that you install a plug-in called Lombok.

Lombok can automatically generate constructors, getters/setters, equals, hashcode, and toString methods for properties at compile time through annotations. The magic that happens is that there are no getter and setter methods in the source code, but there are getter and setter methods in the compiled bytecode file.

2. Create a 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;
Copy after login

3. Configure the connection database in IDEA

  • Before this, create a new Springboot project, which should be relatively simple.

  • After building the SpringBoot project, as shown in the figure below, find the Database

    EasyCode: Generate code with one click
  • ## Proceed as shown in the figure below:

    EasyCode: Generate code with one click
  • ##Then fill in the database name, user name, password. Just click OK. In this case, IDEA is ready to connect to the database.

    EasyCode: Generate code with one click

4. Start generating code

  • Find the table you want to generate here, then right-click, and the section shown below will appear.
    EasyCode: Generate code with one click
  • 点击1所示的位置,选择你要将生成的代码放入哪个文件夹中,选择完以后点击OK即可。

    EasyCode: Generate code with one click
  • 勾选你需要生成的代码,点击OK。

    EasyCode: Generate code with one click
  • 这样的话就完成了代码的生成了,生成的代码如下图所示:

    EasyCode: Generate code with one click

5、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.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
        </dependency>

        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- mysql -->
        <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>
Copy after login

6、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.entity
Copy after login

7、启动项目

在启动项目之前,我们需要先修改两个地方。

  • 在dao层加上@mapper注解

    EasyCode: Generate code with one click
  • 在启动类里面加上@MapperScan("com.vue.demo.dao")注解。

    EasyCode: Generate code with one click
  • 启动项目

    EasyCode: Generate code with one click
  • 测试一下

    EasyCode: Generate code with one click
EasyCode: Generate code with one click

The above is the detailed content of EasyCode: Generate code with one click. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:Java学习指南
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!