mybatisplus根据表自动生成相关类
public class GeneratorTable { //文件生成路径 private static final String OUT_PUT_DIR = "E:\\Generator"; private static final String JDBC_URL = "jdbc:postgresql://ip:port/test?useUnicode=true&characterEncoding=UTF-8"; private static final String USERNAME = "xx"; private static final String PASSWORD = "xxx"; private static final String DRIVER_NAME = "org.postgresql.Driver"; private static final String AUTHOR = "yzh"; //父包名 private static final String PARENT_PACKAGE = "com.xx.xx"; //需要生成的表集合 private static final String[] table_name = new String[]{"table_name"}; public static void main(String[] args) { //1. 全局配置 GlobalConfig config = new GlobalConfig(); //是否支持AR模式 config.setActiveRecord(true) .setAuthor(AUTHOR) .setOutputDir(OUT_PUT_DIR) //生成路径 .setFileOverride(true)//是否文件覆盖,如果多次 .setServiceName("I%sService") //自定义文件命名,注意 %s 会自动填充表实体属性! .setBaseResultMap(true) .setMapperName("%sMapper") //设置日期为Date .setDateType(DateType.ONLY_DATE) .setBaseColumnList(true); //2. 数据源配置 DataSourceConfig dsConfig = new DataSourceConfig(); dsConfig.setDbType(DbType.POSTGRE_SQL) .setUrl(JDBC_URL) .setDriverName(DRIVER_NAME) .setUsername(USERNAME) .setPassword(PASSWORD); //3.策略配置 StrategyConfig stConfig = new StrategyConfig(); stConfig.setCapitalMode(true) // 全局大写命名 .setNaming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略 .setInclude(table_name) ;//生成的表 // .setTablePrefix("tbl_"); // 表前缀 //4.包名策略 PackageConfig pkConfig = new PackageConfig(); pkConfig.setParent(PARENT_PACKAGE)//父包名 .setController("controller") .setEntity("entity") .setService("service") .setMapper("mapper") .setXml("mapper"); //5.整合配置 AutoGenerator ag = new AutoGenerator().setGlobalConfig(config) .setDataSource(dsConfig) .setStrategy(stConfig) .setPackageInfo(pkConfig); ag.execute(); }