Lazy IDEA plugins recommended: EasyCode a key to help you generate the required code

Easycode is a plug-in idea can be generated directly on the entity table data, controller, service, dao, mapper without any coding, simple and powerful.

1, the installation (EasyCode)

I have been saying here is that fitted.

I suggest that you install a plug-in, called Lombok.

Annotations can Lombok manner, at compile time automatically generated constructor property, getter / setter, equals, hashcode, toString method. Appears that there is no magic getter and setter methods in the source code, but there are getter and setter methods in the compiled byte code file.

2, the establishment of a database

 
  1. -- ----------------------------

  2. -- Table structure for user

  3. -- ----------------------------

  4. DROP TABLE IF EXISTS `user`;

  5. CREATE TABLE `user`(

  6. `id`int(11) NOT NULL,

  7. `username` varchar(20) DEFAULT NULL,

  8. `sex` varchar(6) DEFAULT NULL,

  9. `birthday` date DEFAULT NULL,

  10. `address` varchar(20) DEFAULT NULL,

  11. `password` varchar(20) DEFAULT NULL,

  12. PRIMARY KEY (`id`)

  13. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

  14. SET FOREIGN_KEY_CHECKS = 1;

3, connected in the configuration database IDEA

Prior to this, a new Springboot project, this should be relatively straightforward.

Built after SpringBoot project, as shown below, find the Database

As shown in FIG operates as follows:

Then fill in the database name, user name, password. Click OK to. In this case, IDEA connect to the database gets the job done.

4, to start generating code

In this inside to find the table you want to generate, then right, cross-section, as shown below will appear.

Click the position shown in Figure 1, you want to select the generated code into which folder, click OK to complete after the selection.

You need to check the generated code, and click OK.

So completed the code generation, the generated code as shown below:

5, pom.xml

 
  1. <dependency>

  2. <groupId>org.springframework.boot</groupId>

  3. <artifactId>spring-boot-starter</artifactId>

  4. </dependency>

  5.  

  6. <dependency>

  7. <groupId>org.springframework.boot</groupId>

  8. <artifactId>spring-boot-starter-web</artifactId>

  9. </dependency>

  10.  

  11. <dependency>

  12. <groupId>org.projectlombok</groupId>

  13. <artifactId>lombok</artifactId>

  14. <optional>true</optional>

  15. </dependency>

  16.  

  17. <!--热部署-->

  18. <dependency>

  19. <groupId>org.springframework.boot</groupId>

  20. <artifactId>spring-boot-devtools</artifactId>

  21. <optional>true</optional><!-- 这个需要为 true 热部署才有效 -->

  22. </dependency>

  23.  

  24. <!--mybatis-->

  25. <dependency>

  26. <groupId>org.mybatis.spring.boot</groupId>

  27. <artifactId>mybatis-spring-boot-starter</artifactId>

  28. <version>1.3.2</version>

  29. </dependency>

  30.  

  31. <!-- mysql -->

  32. <dependency>

  33. <groupId>mysql</groupId>

  34. <artifactId>mysql-connector-java</artifactId>

  35. <version>5.1.47</version>

  36. </dependency>

  37.  

  38. <!--阿里巴巴连接池-->

  39. <dependency>

  40. <groupId>com.alibaba</groupId>

  41. <artifactId>druid</artifactId>

  42. <version>1.0.9</version>

  43. </dependency>

6, Application.yml

 
  1. server:

  2. port: 8089

  3. spring:

  4. datasource:

  5. url: jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8

  6. username: root

  7. password: 123456

  8. type: com.alibaba.druid.pool.DruidDataSource

  9. driver-class-name: com.mysql.jdbc.Driver

  10.  

  11. mybatis:

  12. mapper-locations: classpath:/mapper/*Dao.xml

  13. typeAliasesPackage: com.vue.demo.entity

7 to start the project

Before starting the project, we need to modify two places.

In the dao layer plus @mapper comment

In the startup class inside with @MapperScan ( "com.vue.demo.dao") notes.

Startup project

have a test

EasyCode usage described here, the children's shoes quickly find useful with them to try it

Published 109 original articles · won praise 175 · views 10000 +

Guess you like

Origin blog.csdn.net/baidu_39322753/article/details/104494294