Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The implementation process of Springboot Integration MybatisPlus

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the implementation process of Springboot integration MybatisPlus". In daily operation, I believe that many people have doubts about the implementation process of Springboot integration MybatisPlus. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Springboot integration MybatisPlus implementation process"! Next, please follow the editor to study!

1. Pom file

4.0.0 com.cun plus 0.0.1-SNAPSHOT jar plus Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.14.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test Test com.baomidou mybatis-plus-boot-starter 2.3 org.freemarker freemarker 2.3.28 com.alibaba druid-spring-boot-starter 1.1.10 org.springframework.boot spring-boot-maven-plugin

2. Create CodeGenerator.java

Package com.cun.plus;import com.baomidou.mybatisplus.enums.IdType;import com.baomidou.mybatisplus.generator.AutoGenerator;import com.baomidou.mybatisplus.generator.config.DataSourceConfig;import com.baomidou.mybatisplus.generator.config.GlobalConfig;import com.baomidou.mybatisplus.generator.config.PackageConfig;import com.baomidou.mybatisplus.generator.config.StrategyConfig;import com.baomidou.mybatisplus.generator.config.rules.DbType;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine Public class CodeGenerator {public static void main (String [] args) {/ / 1. Global configuration GlobalConfig config = new GlobalConfig () Config.setActiveRecord (false) / / whether the AR mode .setAuthor ("len") / / author .setOutputDir (".\ src\\ main\\ java") / / build path .setFileOverride (true) / / file override .setIdType (IdType.AUTO) / / primary key policy .setServiceName ("I%sService") / / is supported. Whether the initials of the resulting service interface are I / / IUserService .setBaseResultMap (true) .setBaseColumnList (true) / / 2. Data source configuration DataSourceConfig dsConfig = new DataSourceConfig (); dsConfig.setDbType (DbType.MYSQL) / / sets the database type .setDriverName ("com.mysql.jdbc.Driver") .setUrl ("jdbc:mysql://localhost:3306/mydatab?useSSL=true&verifyServerCertificate=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8") .setUsername ("root") .setPassword ("lqq74561"); / / 3. Policy configuration / / configure the table name of the table to be generated String [] tableName = {"system_power_type", "system_admin", "company", "power_api", "power_action", "power_action_api", "power_action_group", "power_admin_group", "power_group"}; StrategyConfig stConfig = new StrategyConfig () StConfig.setCapitalMode (true) / / Global uppercase naming .setDbColumnUnderline (true) / / specifies whether the table name field name uses an underscore. SetNaming (NamingStrategy.underline_to_camel) / / naming strategy for database table mapping to entities .setTablePrefix ("tb_") .setInclude (tableName); / / generated table / / 4. Package name policy configuration PackageConfig pkConfig = new PackageConfig (); pkConfig.setParent ("com.cun.plus") .setMapper ("mapper") .setService ("service") .setController ("controller") .setEntity ("entity") .setXml ("mapper"); / / 5. Integration configuration AutoGenerator ag = new AutoGenerator (); ag.setGlobalConfig (config) .setDataSource (dsConfig) .setStrategy (stConfig) .setPackageInfo (pkConfig); / / 6. Execute ag.setTemplateEngine (new FreemarkerTemplateEngine ()); ag.execute ();}}

3. Configure mybatis-plus in application.yml

# mybatis-plusmybatis-plus: # xml mapper-locations: classpath:/mapper/*Mapper.xml # bean typeAliasesPackage: com.cun.plus.entity global-config: # 3: "UUID" Id-type: 3 field-strategy: 2 db-column-underline: true key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator logic-delete-value: 1 logic-not-delete-value: 0 sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector configuration: map-underscore-to-camel-case: true cache-enabled: false # JdbcTypeForNull jdbc-type-for-null: 'null'

4. Create a MybatisPlusConfig.java file

Package com.cun.plus.conf;import org.mybatis.spring.annotation.MapperScan;import org.springframework.context.annotation.Configuration;@Configuration@MapperScan ("com.cun.plus.mapper") public class MybatisPlusConfig {}

Other

Wrapper:MP built-in condition wrapper.

Sql Analyzer: (in MybatisPlusConfig.java)

/ * * SQL execution efficiency plug-in * / @ Bean@Profile ({"dev", "test"}) / / set the dev test environment to enable public PerformanceInterceptor performanceInterceptor () {return new PerformanceInterceptor ();}

At this point, the study on "the implementation process of Springboot integration MybatisPlus" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report