Mybatis-plus根据数据库的表自动生成实体类
第一步:编写组件
@Component
@ConfigurationProperties(prefix = "generator")
@Data
public class MybatisPlusAutoGeneratorBean {
//数据库账号
private String username;
//数据库密码
private String password;
//数据库url地址
private String url;
//数据库驱动
private String driver;
//想要自动生成的数据库的表(可多张)
private String[] dbTableList;
//不生成表的前缀
private String[] prefix;
}
第二步:编写application.yml
# mybatisplus代码生成器配置 generator: username: root password: 123 driver: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/gnnykj_dev?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8 dbTableList: #数据库的表,可多张(自己设置) - ele_branch prefix: - ele - sys
第三步:
第四步:在测试类里面启动生成
@Autowired
MyAutoGenerator myAutoGenerator;
@Test
public void test() {
myAutoGenerator.autoGenerator();
}
下一篇:
MySQL时区错误处理方法
