色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Spring boot整合Mybatis-plus過程解析

瀏覽:51日期:2023-09-13 10:22:27

Mybatis初期使用比較麻煩,需要很多配置文件、實(shí)體類、dao層映射、還有很多其他的配置。初期開發(fā)使用generator可以根據(jù)表結(jié)構(gòu)自動(dòng)生產(chǎn)實(shí)體類、dao層代碼,這樣是可以減輕一部分開發(fā)量;后期mybatis進(jìn)行大量的優(yōu)化,現(xiàn)在可以使用注解版本,自動(dòng)管理dao層和配置文件。

maven 依賴 注意:本文使用的是mysql,數(shù)據(jù)庫依賴就不展示了

<!-- 引入mvbatie -plus starter--><dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>2.3</version> </dependency> <!-- 模板引擎 mybatis使用code生成代碼需要 --><dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.0</version></dependency>

代碼模版引擎需要velocity或freemarker(mybatis-plus默認(rèn)使用velocity,兩者任選其一),這里使用velocity

代碼生成器

public static void main(String[] args) {CodeGeneration codeGeneration = new CodeGeneration();codeGeneration.execute();}/** * * @ClassName: CodeGeneration * @Description: 代碼生成器 */public void execute() {AutoGenerator mpg = new AutoGenerator();// 全局配置GlobalConfig gc = new GlobalConfig();//生成的代碼路徑(系統(tǒng)路徑)gc.setOutputDir('/Users/wangxiaowei/wxw/eclipseWorkSpace/study/src/main/java');gc.setFileOverride(true);gc.setActiveRecord(false);// 不需要ActiveRecord特性的請(qǐng)改為falsegc.setEnableCache(false);// XML 二級(jí)緩存gc.setBaseResultMap(true);// XML ResultMapgc.setBaseColumnList(false);// XML columListgc.setAuthor('wxw');// 作者// 自定義文件命名,注意 %s 會(huì)自動(dòng)填充表實(shí)體屬性!gc.setControllerName('%sController');gc.setServiceName('%sService');gc.setServiceImplName('%sServiceImpl');gc.setMapperName('%sDao');gc.setXmlName('%sMapper');mpg.setGlobalConfig(gc);// 數(shù)據(jù)源配置DataSourceConfig dsc = new DataSourceConfig();dsc.setDbType(DbType.MYSQL);dsc.setDriverName('com.mysql.jdbc.Driver');dsc.setUsername('xxx');//數(shù)據(jù)庫用戶名dsc.setPassword('xxx');//密碼//數(shù)據(jù)庫路徑dsc.setUrl('jdbc:mysql://localhost:30870/horus_dev?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true');mpg.setDataSource(dsc);// 策略配置StrategyConfig strategy = new StrategyConfig();strategy.setTablePrefix(new String[] { '' });// 此處可以修改為您的表前綴strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略// 需要生成的表的名稱,這里app_user_info即為表名strategy.setInclude(new String[] { 'app_user_info',});strategy.setSuperServiceClass(null);strategy.setSuperServiceImplClass(null);strategy.setSuperMapperClass(null);mpg.setStrategy(strategy);// 包配置PackageConfig pc = new PackageConfig();pc.setParent('com.wang.study');//父包,下面的子包均在這父包之下pc.setController('controller');//上面生成的controller類 放到controller子包pc.setService('service');//上面生成的service 放到service子包,下面類似pc.setMapper('dao');pc.setEntity('pojo');pc.setXml('mapper');mpg.setPackageInfo(pc);// 執(zhí)行生成mpg.execute();}

mybatis 基礎(chǔ)配置(這里使用的properties)

#數(shù)據(jù)源spring.datasource.url=jdbc:mysql://localhost:30870/horus_dev?useUnicode=true&characterEncoding=utf-8spring.datasource.username =xxxspring.datasource.password =xxxspring.datasource.type =com.alibaba.druid.pool.DruidDataSource#mapper文件mybatis-plus.mapper-locations=classpath:com/wang/study/mapper/*.xml#數(shù)據(jù)庫表對(duì)應(yīng)的實(shí)體類所在包mybatis-plus.type-aliases-package=com/wang/study/pojo#日志 打印sqllogging.level.com.wang.study.dao=debug

mybatis-plus 分頁,在配置類里添加以下配置

/** * mybatis-plus分頁插件<br> * 文檔:http://mp.baomidou.com<br> */ @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); paginationInterceptor.setDialectType('mysql'); return paginationInterceptor; }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 国产一级一片免费播放刺激 | 日一区二区 | 美女扒开腿让男人桶尿口 | 国产女女视屏免费 | 99aiav国产精品视频 | 欧美一级视频在线观看 | 在线成人天天鲁夜啪视频 | 国产精品线在线精品国语 | 欧美日韩视频免费播放 | 亚洲国产影视 | 日韩一级大毛片欧美一级 | 91高清免费国产自产 | 三级伦理网站 | 成人免费xxxxx在线视频 | 国产亚洲综合久久 | 色伊人国产高清在线 | 男人的亚洲天堂 | 日本aa毛片a级毛片免费观看 | 波多野结衣在线不卡 | 欧美黄色特级视频 | 99福利资源久久福利资源 | 亚洲美女自拍视频 | 午夜视频一区二区 | 亚洲刺激视频 | 美女黄色一级片 | 欧美色性视频 | 国产成人小视频在线观看 | 国产一区二区亚洲精品天堂 | 欧美一级毛片无遮无挡 | 久久综合网址 | 久久这里一区二区精品 | 国产日韩在线播放 | 美女张开腿让男人桶的动态图 | 最新亚洲一区二区三区四区 | 国产精品吹潮在线播放 | 国产成人亚洲综合91精品555 | 亚洲视频手机在线 | 老人久久www免费人成看片 | 日韩免费一级 | a级毛片毛片免费观看永久 a级毛片毛片免费很很综合 | 中文字幕精品在线 |