Easycode is a plug-in of IDEA, which can directly generate entity, controller, Service, DAO, mapper for the data table without any coding, simple and powerful.

1. Install (EasyCode)

It’s already installed in my case.

I recommend you install a plug-in called Lombok.

Lombok automatically generates constructors, getters/setters, equals, hashcode, and toString methods for properties at compile time via annotations. The magic that happens is that there are no getters and setters in the source code, but there are getters and setters in the bytecode files generated by the compilation.

2. Build 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 the code

3. Configure the connection to the database in IDEA

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

After setting up the SpringBoot project, as shown in the figure below, locate the Database

Operate as shown below:

Then fill in the database name, username, and password. Click OK. In this case, IDEA connects to the database.

4. Start generating code

Find the table you want to generate in this, right click, and the screenshot shown below will appear.

Click the location shown in 1, select the folder in which you want to put the generated code, and then click OK.

Check the code you want to generate and click OK.

This completes the code generation, which looks like the following:

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> <! -- This needs to betrueHot deployment only works --> </dependency> <! --mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> < artifactId > mybatis - spring - the boot - starter < / artifactId > < version > 1.3.2 < / version > < / dependency > <! -- mysql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> The < version > 5.1.47 < / version > < / dependency > <! Alibaba </groupId> <artifactId>druid</artifactId> <version>1.0.9</version> </dependency>Copy the code

6, Application. Yml

Server: port: 8089 spring: a 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.entityCopy the code

7. Start the project

Before we can start the project, we need to make two changes.

Annotate the DAO layer with @mapper annotations

Note: mapper notes will be covered in my next post. If you don’t want to visit my homepage, you can just click the link below

Juejin. Cn/post / 684490…

Add the @mapperscan (“com.vue.demo.dao”) annotation to the startup class.

Start the project.

Test it out.

The usage of EasyCode is introduced here, feel useful partners quickly use to try ~

The original link: www.jianshu.com/p/e4192d7c6844