Home >Java >javaTutorial >EasyCode: Generate code with one click
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.
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.
-- ---------------------------- -- 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;
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
点击1所示的位置,选择你要将生成的代码放入哪个文件夹中,选择完以后点击OK即可。
勾选你需要生成的代码,点击OK。
这样的话就完成了代码的生成了,生成的代码如下图所示:
<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>
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
在启动项目之前,我们需要先修改两个地方。
在dao层加上@mapper注解
在启动类里面加上@MapperScan("com.vue.demo.dao")注解。
启动项目
测试一下
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!