本篇內(nèi)容介紹了“mybatis-plus怎么自動生成類”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!

為尼木等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及尼木網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、尼木網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.1.2</version> </dependency> <dependency> <groupId>MySQL</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> </dependency>
CREATE TABLE if not exists `tbl_product_category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category_pic_code` varchar(100) NOT NULL comment '圖片地址id', `name` varchar(255) NOT NULL comment '產(chǎn)品類別名字', `status` bit(1) NOT NULL default 1 comment '0 無效 1有效', `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 comment='產(chǎn)品類別信息';
public static void main(String[] args) {
String projectPath = System.getProperty("user.dir");
String outputDir = projectPath + "/src/main/java"; //生成文件輸出目錄
String author = "duanlsh"; //注釋作者
String entity = "ProductCategory"; //生成文件實體名稱
String entityPrefix = "tbl_"; //前綴
String[] tableName = "tbl_product_category".split(","); //表名多個以 , 分割
String packageName = "com.apple"; //生成文件的 包名
//數(shù)據(jù)庫
String dbUrl = "jdbc:mysql://localhost:3306/grainfull?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC";
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDbType(DbType.MYSQL)
.setUrl(dbUrl)
.setUsername("root")
.setPassword("root")
.setDriverName("com.mysql.cj.jdbc.Driver");
GlobalConfig config = new GlobalConfig();
config.setAuthor(author);
config.setOutputDir(outputDir);
config.setFileOverride(true);
config.setOpen(false); //文件生成完是否打開目錄
config.setEntityName("%sModel");//實體類添加Model
config.setServiceName("%sService");
config.setControllerName("%sController");
config.setServiceImplName("%sServiceImpl");
config.setMapperName("%sMapper");
config.setXmlName("%sMapper");
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig
.setCapitalMode(true)
.setEntityLombokModel(true) //設(shè)置是否使用 lombook
// .setDbColumnUnderline(true)
.setNaming(NamingStrategy.underline_to_camel)
.setColumnNaming(NamingStrategy.underline_to_camel)
.setRestControllerStyle(true)
.setControllerMappingHyphenStyle(true)
// .setSuperEntityClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl")
// .setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper")
.setInclude(tableName)//修改替換成你需要的表名,多個表名傳數(shù)組
.setTablePrefix(entityPrefix)
;
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
//do nothing
}
};
PackageConfig packageConfig = new PackageConfig();
// packageConfig.setModuleName("ProductCategory"); //在parent包下面添加的包名 eg: com.apple.ProductCategory
packageConfig.setParent(packageName);
packageConfig.setController("controller");
packageConfig.setService("service");
packageConfig.setServiceImpl("service.impl");
packageConfig.setEntity("model");
// TemplateConfig templateConfig = new TemplateConfig();
// templateConfig.setEntity("/templates/entity2.java");
// templateConfig.setXml(null);
AutoGenerator mpg = new AutoGenerator();
// mpg.setTemplate(templateConfig);
mpg.setGlobalConfig(config);
mpg.setDataSource(dataSourceConfig);
mpg.setStrategy(strategyConfig);
mpg.setCfg(cfg);
mpg.setPackageInfo(packageConfig);
mpg.execute();
}“mybatis-plus怎么自動生成類”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
網(wǎng)頁題目:mybatis-plus怎么自動生成類
當前地址:http://chinadenli.net/article0/jpsjoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、品牌網(wǎng)站制作、企業(yè)建站、外貿(mào)建站、域名注冊、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)