In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to generate classes automatically by mybatis-plus". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Directory pom depends on executing sqldemo
Pom.xml
Org.springframework.boot spring-boot-starter-web com.baomidou mybatis-plus-generator 3.1.2 mysql mysql-connector-java 8.0.11 org.apache.velocity velocity-engine-core 2.0 org.projectlombok lombok 1.18.8
Execute sql
CREATE TABLE if not exists `category_pic_ int (11) NOT NULL AUTO_INCREMENT, `category_pic_ code `NOT NULL comment 'picture address id', `name` varchar' NOT NULL comment 'product category name, `status`bit (1) NOT NULL default 1 comment' 0 invalid 1 valid', `update_ time`timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `update_ time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP PRIMARY KEY (`id`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 comment=' product category information'
Execute the code
Public static void main (String [] args) {String projectPath = System.getProperty ("user.dir"); String outputDir = projectPath + "/ src/main/java"; / / generate file output directory String author = "duanlsh"; / / comment author String entity = "ProductCategory"; / / generate file entity name String entityPrefix = "tbl_" / / prefix String [] tableName = "tbl_product_category" .split (","); / / multiple table names, split String packageName = "com.apple"; / / generate the package name of the file / / database 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); / / whether to open the directory config.setEntityName ("% sModel"); / / add Model config.setServiceName ("% sService") to the entity class; config.setControllerName ("% sController"); config.setServiceImplName ("% sServiceImpl"); config.setMapperName ("% sMapper"); config.setXmlName ("% sMapper"); StrategyConfig strategyConfig = new StrategyConfig () StrategyConfig .setCapitalMode (true) .setEntityLombokModel (true) / / sets whether to use 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) / / modify and replace with the table name you need Multiple table name passing array .setTablePrefix (entityPrefix) InjectionConfig cfg = new InjectionConfig () {@ Override public void initMap () {/ / do nothing}}; PackageConfig packageConfig = new PackageConfig (); / / packageConfig.setModuleName ("ProductCategory"); / / the package name added under the parent package is 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 ();} "how mybatis-plus automatically generates classes" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.