【Mybatis】Mybatis快取(轉載)
阿新 • • 發佈:2022-04-18
mybatis-plus的官網:
https://www.mybatis-plus.com/guide/generator.html#新增依賴
- 記得導包
`
`<dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.4.1</version> </dependency>
/** * @description: * @author: HaHa * @time: 2022/4/19 20:04 */ public class AutoMain { public static void main(String[] args) { AutoGenerator generator = new AutoGenerator(); // 設定全域性配置 GlobalConfig config = new GlobalConfig(); String s = System.getProperty("user.dir"); config.setOutputDir(s+"/src/main/java"); config.setAuthor("mybatis自動生成"); config.setOpen(false); config.setFileOverride(false); //是否檔案覆蓋 config.setSwagger2(true); config.setServiceName("%sService"); //去掉Service前面的I generator.setGlobalConfig(config); //2、設定資料來源 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl("jdbc:mysql://localhost:3306/admin-springboot?serverTimezone=UTC"); dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("123456789"); dsc.setDbType(DbType.MYSQL); generator.setDataSource(dsc); //3、包的配置 PackageConfig pc = new PackageConfig(); pc.setModuleName("admin"); pc.setParent("com"); pc.setEntity("entity"); pc.setMapper("mapper"); pc.setService("service"); pc.setController("controller"); generator.setPackageInfo(pc); //4、策略配置 StrategyConfig strategy = new StrategyConfig(); strategy.setInclude("sys_user"); // 設定要對映的表名 strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setEntityLombokModel(true); // 自動lombok; strategy.setLogicDeleteFieldName("deleted"); //邏輯欄位,資料庫欄位裡面有deteted,然後自動配置 // 自動填充配置 TableFill gmtCreate = new TableFill("gmt_create", FieldFill.INSERT); TableFill gmtModified = new TableFill("gmt_modified",FieldFill.INSERT_UPDATE); ArrayList<TableFill> tableFills = new ArrayList<>(); tableFills.add(gmtCreate); tableFills.add(gmtModified); strategy.setTableFillList(tableFills); // 樂觀鎖 strategy.setVersionFieldName("version"); strategy.setRestControllerStyle(true); strategy.setControllerMappingHyphenStyle(true); //下劃線相當於/ generator.setStrategy(strategy); generator.execute(); } }