插件EasyCode
使用idea easycode插件,完成代码自动生成
1.下载插件
2.数据库连接
使用idea的database插件链接数据库,选中需要生成代码的数据库表.
3.生成代码
选中表(可以多选),然后右键 EasyCode --> Generate Code
4.生成代码配置确认
按照提示,勾选需要的配置
5.验证
点击 OK ,开始自动生成代码,代码生成如图:
6.添加依赖
生成代码后,程序是不能运行的,因为缺少依赖包.引入依赖的包.
<!-- SpringBoot集成mybatis框架 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
7.MapperScan
在启动类中引入dao目录
package com.example;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.example.dao")
public class TestTestTestApplication {
public static void main(String[] args) {
SpringApplication.run(TestTestTestApplication.class, args);
}
}
8.程序配置确认
在application.properties(yml一样)引入数据库连接和mybatis的mapper.xml配置
server.port=8080
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/dddddd?autoReconnect=true
spring.datasource.username=root
spring.datasource.password=root
mybatis.mapperLocations=classpath:mapper/*Dao.xml
9.验证服务
启动服务,通过接口验证程序
结束.谢谢.