Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use mybatis plus Code Generator

Shulou Source: shulou.com Published: 2022-06-02 08:40:08 10月04日 Update

This article mainly explains the "use of mybatis plus code generator", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "the use of mybatis plus code generator" bar!

Mybatis plus usage

Org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.projectlombok lombok true com.baomidou mybatis-plus-boot-starter 3.1.2 Com.h3database H3 runtime public static void main (String [] args) {/ / Code Generator AutoGenerator mpg = new AutoGenerator () / / Global configuration GlobalConfig gc = new GlobalConfig (); gc.setOutputDir ("D:\\ Develop"); gc.setAuthor ("ivan"); gc.setOpen (false); gc.setFileOverride (true); gc.setBaseResultMap (true); gc.setBaseColumnList (true); / / gc.setSwagger2 (true); entity attribute Swagger2 annotation mpg.setGlobalConfig (gc) / / data source configuration DataSourceConfig dsc = new DataSourceConfig (); dsc.setUrl ("jdbc:mysql://localhost:3306/ivan?useUnicode=true&useSSL=false&characterEncoding=utf8"); / / dsc.setSchemaName ("public"); dsc.setDriverName ("com.mysql.jdbc.Driver"); dsc.setUsername ("root"); dsc.setPassword ("password"); mpg.setDataSource (dsc) / / package configuration PackageConfig pc = new PackageConfig (); pc.setParent ("com.leyou"); mpg.setPackageInfo (pc); / / Custom configuration InjectionConfig cfg = new InjectionConfig () {@ Override public void initMap () {/ / to do nothing}} / / mpg.setCfg (cfg) must be set; / / Policy configuration StrategyConfig strategy = new StrategyConfig (); strategy.setNaming (NamingStrategy.underline_to_camel); strategy.setColumnNaming (NamingStrategy.underline_to_camel); / / strategy.setSuperEntityClass ("com.baomidou.ant.common.BaseEntity"); strategy.setEntityLombokModel (true) Strategy.setRestControllerStyle (true); / / Public parent class / / strategy.setSuperControllerClass ("com.baomidou.ant.common.BaseController"); / / Public field written in the parent class / / strategy.setSuperEntityColumns ("id"); strategy.setInclude (new String [] {"tb_category"}); / / strategy.setControllerMappingHyphenStyle (true); strategy.setTablePrefix ("tb_") Mpg.setStrategy (strategy); mpg.execute ();} Thank you for your reading, this is the content of "how to use mybatis plus Code Generator". After the study of this article, I believe you have a deeper understanding of the use of mybatis plus code generator, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Code generator generation configuration usage method learning content global field entity password that is properties ideas situations data data sources articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia MySQL Shulou Technology Xiaomi