24届春招实习必备技能(一)之MyBatis Plus入门实践详解

2024-01-02 01:52

本文主要是介绍24届春招实习必备技能(一)之MyBatis Plus入门实践详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

MyBatis Plus入门实践详解

一、什么是MyBatis Plus?

MyBatis Plus简称MP,是mybatis的增强工具,旨在增强,不做改变。MyBatis Plus内置了内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求。

官网地址:https://mp.baomidou.com/

mp简介

主要特性

  • 无侵入:只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑

  • 损耗小:启动即会自动注入基本 CURD(增加(Create)、读取(Read)、更新(Update)和删除(Delete)),性能基本无损耗,直接面向对象操作

  • 强大的 CRUD 操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求

  • 支持 Lambda 形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需再担心字段写错

  • 支持主键自动生成:支持多达 4 种主键策略(内含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解决主键问题

  • 支持 ActiveRecord 模式:支持 ActiveRecord 形式调用,实体类只需继承 Model 类即可进行强大的 CRUD 操作

  • 支持自定义全局通用操作:支持全局通用方法注入( Write once, use anywhere )

  • 内置代码生成器:采用代码或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 层代码,支持模板引擎,更有超多自定义配置等您来使用

  • 内置分页插件:基于 MyBatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通 List 查询

  • 分页插件支持多种数据库:支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多种数据库

  • 内置性能分析插件:可输出 Sql 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询

  • 内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作

框架结构

架构

二、MP的内置代码生成器

2.1 使用代码方式

这里使用springboot2.2.4.RELEASE,mybatis plus版本是3.1.2,添加MyBatis Plus对应maven依赖如下:

  <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.1.2</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.3.0</version></dependency><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.29</version></dependency>

代码生成类如下:

public class CodeGenerator {/*** <p>* 读取控制台内容* </p>*/public static String scanner(String tip) {Scanner scanner = new Scanner(System.in);StringBuilder help = new StringBuilder();help.append("请输入" + tip + ":");System.out.println(help.toString());if (scanner.hasNext()) {String ipt = scanner.next();if (StringUtils.isNotBlank(ipt)) {return ipt;}}throw new MybatisPlusException("请输入正确的" + tip + "!");}public static void main(String[] args) {// 代码生成器AutoGenerator mpg = new AutoGenerator();// 全局配置GlobalConfig gc = new GlobalConfig();String projectPath = System.getProperty("user.dir");
//        projectPath = projectPath+"/goods";gc.setOutputDir(projectPath + "/src/main/java");gc.setAuthor("gxm");gc.setOpen(false);// gc.setSwagger2(true); 实体属性 Swagger2 注解mpg.setGlobalConfig(gc);// 数据源配置DataSourceConfig dsc = new DataSourceConfig();dsc.setUrl("jdbc:mysql://localhost:3306/db_baby_shop?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false");// dsc.setSchemaName("public");dsc.setDriverName("com.mysql.cj.jdbc.Driver");dsc.setUsername("root");dsc.setPassword("123456");mpg.setDataSource(dsc);// 包配置PackageConfig pc = new PackageConfig();pc.setModuleName(scanner("模块名"));pc.setParent("com.baby");mpg.setPackageInfo(pc);// 自定义配置InjectionConfig cfg = new InjectionConfig() {@Overridepublic void initMap() {// to do nothing}};// 如果模板引擎是 freemarkerString templatePath = "/templates/mapper.xml.ftl";// 如果模板引擎是 velocity// String templatePath = "/templates/mapper.xml.vm";// 自定义输出配置List<FileOutConfig> focList = new ArrayList<>();// 自定义配置会被优先输出String finalProjectPath = projectPath;focList.add(new FileOutConfig(templatePath) {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!return finalProjectPath + "/src/main/resources/mapper/" + pc.getModuleName()+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;}});/*cfg.setFileCreate(new IFileCreate() {@Overridepublic boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {// 判断自定义文件夹是否需要创建checkDir("调用默认方法创建的目录");return false;}});*/cfg.setFileOutConfigList(focList);mpg.setCfg(cfg);// 配置模板TemplateConfig templateConfig = new TemplateConfig();// 配置自定义输出模板//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别// templateConfig.setEntity("templates/entity2.java");// templateConfig.setService();// templateConfig.setController();templateConfig.setXml(null);mpg.setTemplate(templateConfig);// 策略配置StrategyConfig strategy = new StrategyConfig();strategy.setNaming(NamingStrategy.underline_to_camel);strategy.setColumnNaming(NamingStrategy.underline_to_camel);
//        strategy.setSuperEntityClass("com.manicure.goods.entity.BaseEntity");strategy.setEntityLombokModel(true);strategy.setRestControllerStyle(true);// 公共父类
//        strategy.setSuperControllerClass("com.manicure.goods.controller.common.BaseController");// 写于父类中的公共字段strategy.setSuperEntityColumns("id");strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));strategy.setControllerMappingHyphenStyle(true);strategy.setTablePrefix(pc.getModuleName() + "_");mpg.setStrategy(strategy);mpg.setTemplateEngine(new FreemarkerTemplateEngine());mpg.execute();}}

运行main方法,控制台输入模块名、表名即可:

img

2.2 使用maven插件方式

mybatisplus-maven-plugin插件官网:https://gitee.com/baomidou/mybatisplus-maven-plugin

官网插件

官网地址给了教程,需要先将插件安装到本地仓库mvn clean install,然后才能使用。这里给出一份pom文件如下:

 <plugin><groupId>com.baomidou</groupId><artifactId>mybatisplus-maven-plugin</artifactId><version>1.0</version><configuration><!-- 输出目录(默认java.io.tmpdir) --><outputDir>${project.basedir}/src/main/java</outputDir><!-- 是否覆盖同名文件(默认false) --><fileOverride>true</fileOverride><!-- mapper.xml 中添加二级缓存配置(默认true) --><enableCache>true</enableCache><!-- 是否开启 ActiveRecord 模式(默认true) --><activeRecord>false</activeRecord><!-- 数据源配置,( **必配** ) --><dataSource><driverName>com.mysql.jdbc.Driver</driverName><url>jdbc:mysql://127.0.0.1:3306/lab?serverTimezone=Asia/Shanghai</url><username>root</username><password>123456</password></dataSource><strategy><!-- 字段生成策略,四种类型,从名称就能看出来含义:nochange(默认),underline_to_camel,(下划线转驼峰)remove_prefix,(去除第一个下划线的前部分,后面保持不变)remove_prefix_and_camel(去除第一个下划线的前部分,后面转驼峰) --><naming>remove_prefix_and_camel</naming><!-- 表前缀 --><tablePrefix></tablePrefix><!--Entity中的ID生成策略(默认 id_worker)--><idGenType></idGenType><!--自定义超类--><!--<superServiceClass>com.baomidou.base.BaseService</superServiceClass>--><!-- 要包含的表 与exclude 二选一配置--><!--<include>--><!--<property>sec_user</property>--><!--<property>table1</property>--><!--</include>--><!-- 要排除的表 --><!--<exclude>--><!--<property>schema_version</property>--><!--</exclude>--></strategy><packageInfo><!-- 父级包名称,如果不写,下面的service等就需要写全包名(默认com.baomidou) --><parent>com.jane</parent><!--service包名(默认service)--><service>service</service><!--serviceImpl包名(默认service.impl)--><serviceImpl>service.impl</serviceImpl><!--entity包名(默认entity)--><entity>entity</entity><!--mapper包名(默认mapper)--><mapper>mapper</mapper><!--xml包名(默认mapper.xml)--><xml>mapper.xml</xml></packageInfo><template><!-- 定义controller模板的路径 --><!--<controller>/template/controller1.java.vm</controller>--></template></configuration><dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.13</version></dependency></dependencies>
</plugin>

然后如下图所示,执行命令即可:

mvn命令

三、传统SSM中使用MyBatis Plus

也就是说以前使用xml配置时(非SpringBoot)与MyBatis Plus整合。

3.1 引入依赖

如下是一些必要的依赖(你可以根据项目需要引入其他依赖):

<dependencies>
<!-- mp依赖mybatisPlus 会自动的维护Mybatis 以及MyBatis-spring相关的依赖-->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><version>2.3</version>
</dependency>   
<!--junit -->
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.9</version>
</dependency>
<!-- log4j -->
<dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version>
</dependency>
<!-- c3p0 -->
<dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.2</version>
</dependency>
<!-- mysql -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.37</version>
</dependency>
<!-- spring -->
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.10.RELEASE</version>
</dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>4.3.10.RELEASE</version>
</dependency></dependencies>

3.2 MP配置

applicationContext.xml中MP配置如下:

<!--  配置SqlSessionFactoryBean Mybatis提供的: org.mybatis.spring.SqlSessionFactoryBeanMP提供的:com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean--><bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"><!-- 数据源 --><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:mybatis-config.xml"></property><!-- 别名处理 --><property name="typeAliasesPackage" value="com.jane.mp.beans"></property>   <!-- 注入全局MP策略配置 --><property name="globalConfig" ref="globalConfiguration"></property></bean><!-- 定义MybatisPlus的全局策略配置--><bean id ="globalConfiguration" class="com.baomidou.mybatisplus.entity.GlobalConfiguration"><!-- 在2.3版本以后,dbColumnUnderline 默认值就是true --><property name="dbColumnUnderline" value="true"></property><!-- 全局的主键策略 --><property name="idType" value="0"></property><!-- 全局的表前缀策略配置 --><property name="tablePrefix" value="tbl_"></property></bean>

需要注意的是,这里sqlSessionFactoryBean从mybatis的org.mybatis.spring.SqlSessionFactoryBean换成了MyBatis Plus的com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean。

当然还有其他配置,比如mapper扫描器、mapperxml配置等,

四、SpringBoot整合MyBatis Plus

SpringBoot大大简化了开发配置,提高了开发效率。

4.1 引入依赖

MyBatis-Plus 从 3.0.3 之后移除了代码生成器与模板引擎的默认依赖,需要手动添加相关依赖。

 <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.1.2</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.3.0</version></dependency>
<!-- 代码生成器默认模板引擎是freemarker --><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.29</version></dependency>

4.2 编写配置类

//Spring boot方式
@EnableTransactionManagement
@Configuration
@MapperScan("com.baomidou.cloud.service.*.mapper*")
public class MybatisPlusConfig {@Beanpublic PaginationInterceptor paginationInterceptor() {PaginationInterceptor paginationInterceptor = new PaginationInterceptor();// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false// paginationInterceptor.setOverflow(false);// 设置最大单页限制数量,默认 500 条,-1 不受限制// paginationInterceptor.setLimit(500);// 开启 count 的 join 优化,只针对部分 left joinpaginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));return paginationInterceptor;}
}

PaginationInterceptor 是MyBatis Plus的分页插件,同样有对应xml配置方式。如下可以在mybatis-config.xml里面注册:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><plugins><plugin interceptor="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></plugin></plugins></configuration>

或者可以在applicationContext.xml中注册:

<!--  配置SqlSessionFactoryBean 
Mybatis提供的: org.mybatis.spring.SqlSessionFactoryBean
MP提供的:com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
-->
<bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 别名处理 -->
<property name="typeAliasesPackage" value="com.atguigu.mp.beans"></property>    
<!-- 注入全局MP策略配置 -->
<property name="globalConfig" ref="globalConfiguration"></property>
<!-- 插件注册 -->
<property name="plugins"><list><!-- 注册分页插件 --><bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></bean><!-- 注册执行分析插件 --><bean class="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor"><property name="stopProceed" value="true"></property></bean><!-- 注册性能分析插件 --><bean class="com.baomidou.mybatisplus.plugins.PerformanceInterceptor"><property name="format" value="true"></property><!-- <property name="maxTime" value="5"></property> --></bean><!-- 注册乐观锁插件 --><bean class="com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor"></bean></list>
</property></bean>

4.3 application.properties关于MP的配置

配置实例如下:

spring.datasource.url=jdbc:mysql://localhost:3306/db_baby_shop?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driverClassName=com.mysql.jdbc.Drivermybatis-plus.mapper-locations=classpath*:mapper/**/*.xml
mybatis-plus.type-aliases-package=com.jane.mapper

4.4 生成代码

使用代码生成类或者maven插件进行生成,具体参考4.2

五、主键策略与表及字段命名策略

5.1 主键策略选择

MP支持以下4中主键策略,可根据需求自行选用。

什么是Sequence?简单来说就是一个分布式高效有序ID生产黑科技工具,思路主要是来源于Twitter-Snowflake算法。MP在Sequence的基础上进行部分优化,用于产生全局唯一ID,ID_WORDER设置为默认配置。

5.2 表及字段命名策略选择

在MP中建议数据库表名 和 表字段名采用驼峰命名方式, 如果采用下划线命名方式 请开启全局下划线开关,如果表名字段名命名方式不一致请注解指定。

这么做的原因是为了避免在对应实体类时产生的性能损耗,这样字段不用做映射就能直接和实体类对应。当然如果项目里不用考虑这点性能损耗,那么你采用下滑线也是没问题的,只需要在生成代码时配置dbColumnUnderline属性就可以。

以前xml中可能配置如下:

<bean id ="globalConfiguration" class="com.baomidou.mybatisplus.entity.GlobalConfiguration"><!-- 在2.3版本以后,dbColumnUnderline 默认值就是true --><property name="dbColumnUnderline" value="true"></property><!-- 全局的主键策略 --><property name="idType" value="0"></property><!-- 全局的表前缀策略配置 --><property name="tablePrefix" value="tbl_"></property>
</bean>

5.3 FieldStrategy 字段空值策略判断

如下枚举类所示,有三种策略:

public enum FieldStrategy {IGNORED(0, "忽略判断"),NOT_NULL(1, "非 NULL 判断"),NOT_EMPTY(2, "非空判断");//...
}    

解释说明如下:

IGNORED:不管有没有有设置属性,所有的字段都会设置到insert语句中,如果没设置值,全为null,这种在update 操作中会有风险,把有值的更新为null

NOT_NULL:也是默认策略,也就是忽略null的字段,不忽略""

NOT_EMPTY:为null,为空串的忽略,就是如果设置值为null,“”,不会插入数据库

六、MybatisX idea 快速开发插件

MybatisX 辅助 idea 快速开发插件,为效率而生。可以实现java 与 xml 跳转,根据 Mapper接口中的方法自动生成 xml结构

官方安装: File -> Settings -> Plugins -> Browse Repositories… 输入 mybatisx 安装下载

Jar 安装: File -> Settings -> Plugins -> Install plugin from disk… 选中 mybatisx…jar 点击下载安装

插件

安装完如下实例:

小鸟图案

七、自动生成的内容

其实这里是在MyBatis Plus通用CRUD与条件构造器使用及SQL自动注入原理分析后面补充的,主要是想说明service层。

如下图所示,MP的代码生成器可生成 : 实体类 (可以选择是否支持 AR)、 Mapper接口、 Mapper映射文件 、 Service层、 Controller层。

包结构图

其中mapper.xml类似如下包含一个返回结果字段属性映射与一个通用查询结果列。

<mapper namespace="com.jane.mapper.MaintainMapper"><!--开启二级缓存--><cache type="org.mybatis.caches.ehcache.LoggingEhcache"/><resultMap id="BaseResultMap" type="com.jane.entity.Maintain"><id column="id" property="id" />`在这里插入代码片`<result column="equip_id" property="equipId" /><result column="user_id" property="userId" /><result column="time" property="time" /><result column="content" property="content" /></resultMap><!-- 通用查询结果列--><sql id="Base_Column_List">id, equip_id AS equipId, user_id AS userId, time, content</sql>
</mapper>

不过这些不是我们的重点。在看过MyBatis Plus通用CRUD与条件构造器使用及SQL自动注入原理分析后我们知道了继承BaseMapper就能获取通用的CRUD方法。但是通常controller不会直接调用mapper接口的而是调用service。MP同样为我们考虑到了这一点,为我们生成了service与serviceImpl。

以IUserService为例我们看到其继承自IService,其实现类继承自ServiceImpl<UserMapper, User>并实现了IUserService接口。这样我们的UserServiceImpl就拥有了ServiceImpl提供的通用CRUD能力。

public interface IUserService extends IService<User> {}
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {}

那么ServiceImpl提供了哪些能力?如何提供的?

ServiceImpl源码如下:

/**/*** IService 实现类( 泛型:M 是 mapper 对象,T 是实体 , PK 是主键泛型 )** @author hubin* @since 2018-06-23*/
@SuppressWarnings("unchecked")
public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {protected Log log = LogFactory.getLog(getClass());@Autowiredprotected M baseMapper;@Overridepublic M getBaseMapper() {return baseMapper;}//...public boolean save(T entity) {return retBool(baseMapper.insert(entity));}//...}

可以看到其主要是根据baseMapper来实现CRUD能力的,这就要要求你的mapper必须继承自BaseMapper。

八、SpringBoot整合Mybatis Plus常见配置

常见配置如下所示:

mybatis-plus:mapper-locations: classpath:/mapper/**/*Mapper.xml #mapper映射文件路径typeAliasesPackage: com.jane.**.domain #实体包扫描global-config:id-type: 2 #主键类型  全局唯一ID,内容为空自动填充(默认配置),对应数字 2field-strategy: 1 #字段策略 IGNORED-0:"忽略判断",NOT_NULL-1:"非 NULL 判断"),NOT_EMPTY-2:"非空判断"db-column-underline: true #表名、字段名、是否使用下划线命名capital-mode: false #是否大写命名sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector #逻辑删除注入器logic-not-delete-value: 0 #逻辑未删除值(默认为 0)logic-delete-value: 1 #逻辑已删除值(默认为 1)configuration:map-underscore-to-camel-case: true #下划线转驼峰cache-enabled: false # 是否开启缓存

写在最后

编程严选网(www.javaedge.cn),程序员的终身学习网站已上线!

如果这篇【文章】有帮助到你,希望可以给【JavaGPT】点个赞👍,创作不易,如果有对【后端技术】、【前端领域】感兴趣的小可爱,也欢迎关注❤️❤️❤️ 【JavaGPT】❤️❤️❤️,我将会给你带来巨大的【收获与惊喜】💝💝💝!

这篇关于24届春招实习必备技能(一)之MyBatis Plus入门实践详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/561035

相关文章

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

Debezium 与 Apache Kafka 的集成方式步骤详解

《Debezium与ApacheKafka的集成方式步骤详解》本文详细介绍了如何将Debezium与ApacheKafka集成,包括集成概述、步骤、注意事项等,通过KafkaConnect,D... 目录一、集成概述二、集成步骤1. 准备 Kafka 环境2. 配置 Kafka Connect3. 安装 D

Java中ArrayList和LinkedList有什么区别举例详解

《Java中ArrayList和LinkedList有什么区别举例详解》:本文主要介绍Java中ArrayList和LinkedList区别的相关资料,包括数据结构特性、核心操作性能、内存与GC影... 目录一、底层数据结构二、核心操作性能对比三、内存与 GC 影响四、扩容机制五、线程安全与并发方案六、工程

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

Spring Cloud LoadBalancer 负载均衡详解

《SpringCloudLoadBalancer负载均衡详解》本文介绍了如何在SpringCloud中使用SpringCloudLoadBalancer实现客户端负载均衡,并详细讲解了轮询策略和... 目录1. 在 idea 上运行多个服务2. 问题引入3. 负载均衡4. Spring Cloud Load

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

golang内存对齐的项目实践

《golang内存对齐的项目实践》本文主要介绍了golang内存对齐的项目实践,内存对齐不仅有助于提高内存访问效率,还确保了与硬件接口的兼容性,是Go语言编程中不可忽视的重要优化手段,下面就来介绍一下... 目录一、结构体中的字段顺序与内存对齐二、内存对齐的原理与规则三、调整结构体字段顺序优化内存对齐四、内

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为