MyBatis Generator介紹及使用方法
手動編寫 SQL 語句和映射實體類的過程常常是繁瑣且易出錯的。這時,我們就可以借助 MyBatis Generator (MBG) 這個強大的工具來自動化生成這部分代碼。
1.什么是 MyBatis Generator
MyBatis Generator 是一款針對 MyBatis 或 iBATIS 設計的代碼生成器,由 MyBatis 官方提供。它可以生成 MyBatis 的 Java 實體類、mapper.xml 文件以及對應的 Mapper 接口,極大地減少了開發(fā)人員手寫 SQL 語句和映射實體類的工作量,提高了開發(fā)效率。
2.使用 MyBatis Generator
2.1 導入依賴
首先,我們需要在項目中添加 MyBatis Generator 的依賴:
<!-- MyBatis 生成器 -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis-generator.version}</version>
</dependency>當然,為了完成的完成整套流程,我們還需要一些相關的其他依賴,如 MyBatis、PageHelper、Druid 和 MySQL 驅動:
<!-- SpringBoot整合MyBatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-starter.version}</version>
</dependency>
<!-- MyBatis分頁插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-starter.version}</version>
</dependency>
<!-- 集成druid連接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- Mysql數(shù)據(jù)庫驅動 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector.version}</version>
</dependency>注意:上面的
${}部分的版本號需要根據(jù)具體項目的實際情況進行調整。
2.2 application 配置
在 Spring Boot 的 application.yml 配置文件中進行一些基本的配置,主要包括數(shù)據(jù)源的配置、MyBatis 的相關配置:
# 配置數(shù)據(jù)源
spring:
datasource:
url: jdbc:mysql://localhost:3306/<database>?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
username: <username>
password: <password>
# Mybatis 相關配置
mybatis:
# 配置映射文件路徑
mapper-locations:
- classpath:mapper/*.xml
- classpath:mbg/mapper/*/*.xml下面是對上面基本配置的簡單說明:
- 將上述數(shù)據(jù)源配置中的
<database>、<username>和<password>換為你具體的連接信息; - 為了便于區(qū)分 MyBatis Generator 自動生成的 mapper.xml 和我們自己手寫的 mapper.xml,我們約定自己寫的映射文件放在
resources/mapper目錄下,而 MyBatis Generator 自動生成的映射文件放在resources/mbg/mapper目錄下。
2.3 添加 Java 配置
為了讓 Spring Boot 能夠自動掃描到生成的 Mapper 接口,我們需要準備一個配置類通過在 Java 配置類上添加 @MapperScan 注解來指定掃描路徑。
/**
* MyBatis 配置類(掃描 Mapper 接口)
*/
@MapperScan({"cn.javgo.learningmybatis.mapper","cn.javgo.learningmybatis.mbg.mapper"})
@SpringBootConfiguration
public class MyBatisConfig {
}注意,上面我們同樣約定自己寫的 Mapper 接口放在 cn.javgo.learningmybatis.mapper 包下,而 MyBatis Generator 自動生成的 Mapper 接口放在 cn.javgo.learningmybatis.mbg.mapper 包下。
2.4 MBG 配置
在 resources 目錄下準備一個 generator.properties 配置文件,用于配置數(shù)據(jù)庫連接的基本信息:
jdbc.driverClass=com.mysql.cj.jdbc.Driver jdbc.connectionURL=jdbc:mysql://localhost:3306/<database>?useSSL=false&serverTimezone=UTC jdbc.username=<username> jdbc.password=<password>
注意:你需要將上述數(shù)據(jù)源配置中的
<database>、<username>和<password>換為你具體的連接信息。
然后,需要在 resources 目錄下創(chuàng)建一個 MBG 的配置文件 generatorConfig.xml,配置好需要連接的數(shù)據(jù)庫,以及指定生成的實體類、Mapper 接口和 XML 映射文件的位置。
配置文件的具體內容根據(jù)實際情況設置,以下是一個簡單的例子:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 導入屬性配置 -->
<properties resource="generator.properties"/>
<!-- MBG 上下文環(huán)境
id:上下文環(huán)境唯一標識,必須唯一
targetRuntime:生成的目標運行環(huán)境
MyBatis3:代表生成MyBatis3.x版本的代碼
MyBatis3Simple:新版本的生成器
MyBatis3DynamicSql:新版本的生成器
defaultModelType:生成的默認Model類型
flat:代表生成的Model都是一個個的獨立的類,例如生成Dept類(推薦)
hierarchical:代表生成的Model類會按照層級進行組織,例如生成Dept、DeptMapper、DeptExample三個類
-->
<context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
<!-- 配置SQL語句中的前置分隔符 -->
<property name="beginningDelimiter" value="`"/>
<!-- 配置SQL語句中的后置分隔符 -->
<property name="endingDelimiter" value="`"/>
<!-- 配置生成Java文件的編碼 -->
<property name="javaFileEncoding" value="UTF-8"/>
<!--生成mapper.xml時覆蓋原文件-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
<!-- 為模型生成序列化方法-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!-- 為生成的Java模型創(chuàng)建一個toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!--可以自定義生成model的代碼注釋
type:自定義注釋生成器的類全限定名
-->
<commentGenerator type="cn.javgo.learningmybatis.mbg.CommentGenerator">
<!-- 是否阻止生成的注釋 -->
<property name="suppressAllComments" value="true"/>
<!-- 是否阻止生成的注釋包含時間戳 -->
<property name="suppressDate" value="true"/>
<!-- 是否添加數(shù)據(jù)庫表的備注信息 -->
<property name="addRemarkComments" value="true"/>
</commentGenerator>
<!-- 配置數(shù)據(jù)庫連接 -->
<jdbcConnection driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.username}"
password="${jdbc.password}">
<!-- 配置數(shù)據(jù)庫連接的屬性信息
autoReconnect:是否自動重連
allowMultiQueries:是否允許執(zhí)行多條SQL語句
useUnicode:是否使用Unicode字符集
characterEncoding:設置字符集編碼
useSSL:是否使用SSL
nullCatalogMeansCurrent:是否將null catalog看作當前catalog(解決 MySql 8.0 以上版本不生成指定數(shù)據(jù)庫代碼的問題)
-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!-- 配置實體類的包名和位置
targetPackage:生成的實體類存放的包名
targetProject:生成的實體類存放的位置
-->
<javaModelGenerator targetPackage="cn.javgo.learningmybatis.mbg.model" targetProject="src/main/java">
<!-- 是否允許子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="true"/>
<!-- 是否對model添加構造函數(shù) -->
<property name="constructorBased" value="true"/>
<!-- 是否對類CHAR類型的列的數(shù)據(jù)進行trim操作 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 配置SQL映射文件的包名和位置
targetPackage:生成的SQL映射文件存放的包名
targetProject:生成的SQL映射文件存放的位置
-->
<sqlMapGenerator targetPackage="cn.javgo.learningmybatis.mbg.mapper" targetProject="src/main/resources">
<!-- 是否允許子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 配置Mapper接口的包名和位置
type:選擇怎么生成mapper接口(推薦使用XMLMAPPER)
XMLMAPPER:生成XML對應的Mapper接口
ANNOTATEDMAPPER:生成基于注解的Mapper接口
MIXEDMAPPER:生成XML對應的Mapper接口,同時也生成基于注解的Mapper接口
targetPackage:生成的Mapper接口存放的包名
targetProject:生成的Mapper接口存放的位置
-->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.javgo.learningmybatis.mbg.mapper"
targetProject="src/main/java">
<!-- 是否允許子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 指定數(shù)據(jù)庫表
tableName:數(shù)據(jù)庫表名
domainObjectName:生成的實體類名(默認去掉下劃線,駝峰命名)
-->
<table tableName="student">
<!-- 配置自增主鍵
column:指定獲取自增主鍵的列
sqlStatement:指定獲取自增主鍵的SQL語句
identity:指定是否為自增主鍵
-->
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
</context>
</generatorConfiguration>上述示例中注釋已經很完善了,不再過多解釋,根據(jù)實際需要進行調整即可。
注意:
MyBatis Generator 在運行時會根據(jù)配置文件中指定的路徑生成所需的文件。如果路徑中的目錄已經存在,MBG 會直接在其中創(chuàng)建文件。如果路徑中的某個目錄不存在,MBG 會嘗試創(chuàng)建這個目錄。
然而,有一點需要注意:MBG 只會嘗試創(chuàng)建最后一級的目錄,而不會創(chuàng)建整個目錄路徑。 例如,如果配置中的
targetProject是src/main/java,而targetPackage是cn.javgo.learningmybatis.mbg.model,則 MBG 會在src/main/java目錄下創(chuàng)建cn/javgo/learningmybatis/mbg/model目錄。前提是src/main/java這個目錄已經存在。如果src/main/java不存在,MBG 將無法創(chuàng)建文件。因此,通常我們需要提前創(chuàng)建好 MBG 配置中指定的項目路徑(
targetProject),這樣 MBG 才能正確生成文件。而對于包路徑(targetPackage),MBG 會自動創(chuàng)建,我們無需手動創(chuàng)建。
如果你想自定義 MBG 生成的代碼,可以自定義一個 CommentGenerator 來繼承 DefaultCommentGenerator 進行個性化的定制,這對應了上面配置文件中的 commentGenerator 標簽部分。
比如我們可以自定義實體類代碼的生成,在實體類代碼上添加 Swagger 注解的支持:
package cn.javgo.learningmybatis.mbg;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.DefaultCommentGenerator;
import org.mybatis.generator.internal.util.StringUtility;
import java.util.Properties;
/**
* 自定義注釋生成器
*/
public class CommentGenerator extends DefaultCommentGenerator {
// 是否添加數(shù)據(jù)庫表的注釋
private boolean addRemarkComments = false;
// Example 類名后綴
private static final String EXAMPLE_SUFFIX = "Example";
// Mapper 類名后綴
private static final String MAPPER_SUFFIX = "Mapper";
// ApiModelProperty 注解類的全限定名(Swagger)
private static final String API_MODEL_PROPERTY_FULL_CLASS_NAME = "io.swagger.annotations.ApiModelProperty";
/**
* 設置用戶配置的參數(shù)
* @param properties 用戶配置的參數(shù)
*/
@Override
public void addConfigurationProperties(Properties properties) {
// 調用父類方法保證父類方法可以正常使用
super.addConfigurationProperties(properties);
// 從 properties 中獲取 addRemarkComments 參數(shù)值來判斷是否添加數(shù)據(jù)庫表的注釋
this.addRemarkComments = Boolean.parseBoolean(properties.getProperty("addRemarkComments"));
}
/**
* 給字段添加注釋
* @param field 字段
* @param introspectedTable 數(shù)據(jù)庫表
* @param introspectedColumn 數(shù)據(jù)庫表字段
*/
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
// 獲取數(shù)據(jù)庫表字段的注釋
String remarks = introspectedColumn.getRemarks();
// 根據(jù)參數(shù)和備注信息判斷是否添加備注信息
if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
// 如果存在特殊字符,需要轉義
if (remarks.contains("\"")) {
remarks = remarks.replace("\"", "'");
}
// 給 model 的字段添加 Swagger 注解
field.addJavaDocLine("@ApiModelProperty(value = \"" + remarks + "\")");
}
}
/**
* 給 Java 文件添加注釋
* @param compilationUnit Java 文件
*/
@Override
public void addJavaFileComment(CompilationUnit compilationUnit) {
// 調用父類方法保證父類方法可以正常使用
super.addJavaFileComment(compilationUnit);
// 獲取 Java 文件的全限定名
String fullyQualifiedName = compilationUnit.getType().getFullyQualifiedName();
// 如果不是 Mapper 類或者 Example 類,就添加 Swagger 注解類的導入(因為只有 model 類需要添加 Swagger 注解)
if (!fullyQualifiedName.contains(MAPPER_SUFFIX) && !fullyQualifiedName.contains(EXAMPLE_SUFFIX)) {
// 添加 Swagger 注解類的導入
compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME));
}
}
}使用 Swagger 需要在項目的 pom 文件中添加對應的依賴:
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>注意,上述 ${springfox-swagger.version} 版本號需要根據(jù)實際情況進行選擇。
TIP:
關于 Swagger API 文檔生成工具的使用請自行閱讀官方文檔或主頁也有對應教程,此處不再詳細展開。
2.5 生成代碼
配置完成后,你可以通過命令行、Maven 插件或者直接使用 Java API 來運行 MBG。
如果是使用 Java API 的方式,我們需編寫一個 Generator 類,完成如下代碼編寫后直接運行 main 方法即可:
package cn.javgo.learningmybatis.mbg;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
* 通過 Java API 的方式運行 MyBatis Generator
*/
public class Generator {
public static void main(String[] args) throws Exception {
// 存儲運行 MBG 時的警告信息
List<String> warnings = new ArrayList<>();
// 生成的代碼重復時,覆蓋原代碼
boolean overwrite = true;
// 讀取 MBG 配置文件 generatorConfig.xml
InputStream inputStream = Generator.class.getResourceAsStream("/generatorConfig.xml");
// 傳入警告信息創(chuàng)建配置解析器(用于解析 generatorConfig.xml 配置文件)
ConfigurationParser cp = new ConfigurationParser(warnings);
// 解析配置文件
Configuration config = cp.parseConfiguration(inputStream);
// 關閉輸入流
assert inputStream != null;
inputStream.close();
// 創(chuàng)建 DefaultShellCallback 對象,用于解決重復文件覆蓋問題
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
// 創(chuàng)建 MyBatisGenerator 對象,執(zhí)行生成代碼
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
// 執(zhí)行生成代碼
myBatisGenerator.generate(null);
// 輸出警告信息
for (String warning : warnings) {
System.out.println(warning);
}
}
}如果使用 Maven 插件,只需要在 pom.xml 中添加以下插件即可:
<!-- MyBatis 生成器 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.0</version>
<!-- 基本信息配置 -->
<configuration>
<!-- MyBatis Generator 配置文件 -->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<!-- 允許移動生成的文件 -->
<overwrite>true</overwrite>
<!-- 是否自動覆蓋 -->
<verbose>true</verbose>
</configuration>
</plugin>然后運行以下 Maven 命令即可:
$ mvn mybatis-generator:generate
如果是通過命令行的方式,可以運行如下命令,JAR 包需要為具體版本的包,同時提供配置文件:
$ java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml
運行成功后,你會在指定的包中看到生成的代碼結構信息:

可以查看 MBG 生成的 StudentMapper 接口,發(fā)現(xiàn)已經包含了基本的 CRUD 方法,具體 SQL 實現(xiàn)也已經在 mapper.xml 中生成了,單表 CRUD 直接調用對應方法即可滿足日常需求。同時,生成的代碼中你還會發(fā)現(xiàn)有一個對應的 StudentExample 類,可以將其理解為一個條件構造器,用于構建 SQL 語句中的各種條件。

2.6 基本 CRUD 操作
基于上述生成的代碼,我們的持久層任務也就完成了,接下來只需要編寫對應的控制層和業(yè)務邏輯層進行合理的調用即可。例如下面是一個對應的 StudentServiceImpl 業(yè)務邏輯層實現(xiàn)類:
/**
* 學生業(yè)務實現(xiàn)類
*/
@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public void save(Student student) {
studentMapper.insert(student);
}
@Override
public void update(Student student) {
studentMapper.updateByPrimaryKeySelective(student);
}
@Override
public void delete(Long id) {
studentMapper.deleteByPrimaryKey(id);
}
@Override
public Student select(Long id) {
return studentMapper.selectByPrimaryKey(id);
}
@Override
public List<Student> selectAll(int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
return studentMapper.selectByExample(new StudentExample());
}
}3.進階使用 MyBatis Generator
除了上述的基本單表 CRDU 外,我們還可以通過諸如構造條件、子查詢、分組、連接和使用高級映射等方式來利用好 MyBatis Generator。
在開始之前,我們先介紹一下 Example 類。MyBatis Generator (MBG) 為每個數(shù)據(jù)庫表生成了一個對應的 Example 類。Example 類是一個很強大的工具,它主要用于生成動態(tài) SQL 語句。
Example 類允許你構建復雜的 WHERE 子句,而無需直接在 mapper 文件中硬編碼 SQL,它包含了很多用于構建 WHERE 子句的方法。每個方法都對應一個 SQL 比較運算符,比如 “=”, “<>”, “>”, “<”, “LIKE” 等。你可以動態(tài)地添加、修改或刪除查詢條件。使用 Example 類,你可以構建幾乎任何類型的查詢,包括帶有 AND 和 OR 子句的查詢,帶有子查詢的查詢等。
在使用 Example 類時,你需要創(chuàng)建一個 Example 對象,然后通過調用該對象的 createCriteria() 方法創(chuàng)建一個 Criteria 對象。然后你可以在 Criteria 對象上調用各種方法來添加查詢條件。
3.1 基于條件的 CRUD
條件查詢、條件修改和條件刪除都可以通過 Example 類來實現(xiàn),每個生成的映射器都有一個相應的 Example 類。例如,對于我們上面測試的 Student 表,MBG 會生成一個 StudentExample 類。

我們可以通過創(chuàng)建一個 StudentExample 對象,并添加條件來進行查詢,修改或刪除。
例如,要查詢 ID 大于 10 的用戶,你可以這樣做:
@Override
public List<Student> selectByCondition() {
// 構建一個 Example 對象
StudentExample example = new StudentExample();
// 添加條件
example.createCriteria().andIdGreaterThan(10L);
// 執(zhí)行查詢
return studentMapper.selectByExample(example);
} 你也可以創(chuàng)建多個 Criteria 對象,并通過 OR 連接它們,來實現(xiàn)更復雜的查詢。例如,要查詢 ID 大于 10 或學生姓名為 “john” 的用戶,你可以這樣做:
@Override
public List<Student> selectByCondition() {
// 構建一個 Example 對象
StudentExample example = new StudentExample();
// 添加條件
example.or().andIdGreaterThan(10L);
example.or().andNameEqualTo("john");
// 執(zhí)行查詢
return studentMapper.selectByExample(example);
}此外,Example 類也支持排序,你可以通過調用 Example 對象的 setOrderByClause 方法來添加排序條件。例如,要按照 ID 升序查詢用戶,你可以這樣做:
@Override
public List<Student> selectByCondition() {
// 構建一個 Example 對象
StudentExample example = new StudentExample();
// 添加條件(desc 降序, asc 升序)
example.setOrderByClause("id asc");
// 執(zhí)行查詢
return studentMapper.selectByExample(example);
}對于條件修改和刪除,你也可以使用 Example 類。例如,刪除 ID 大于 10 的用戶:
@Override
public void deleteByCondition() {
// 構建一個 Example 對象
StudentExample example = new StudentExample();
// 添加條件
example.createCriteria().andIdGreaterThan(10L);
// 執(zhí)行刪除
studentMapper.deleteByExample(example);
}可見,Example 類是一個非常有用的工具,它可以讓你的 SQL 查詢更加動態(tài)和靈活。
TIP:
但是也需要注意,過度使用
Example類可能會導致你的代碼變得復雜和難以理解。因此,對于復雜的查詢,有時直接編寫 SQL 可能是一個更好的選擇。
3.2 子查詢、Group 與 Join 查詢
MBG 主要用來生成簡單的基于單表的 CRUD 操作的代碼。對于更復雜的 SQL 操作,比如子查詢、Group 查詢和 Join 查詢,MBG 并不直接支持。這些復雜查詢需要你自己在 Mapper 的 xml 文件或基于注解編寫相應的 SQL。
3.3 一對一查詢、一對多查詢
一對一和一對多查詢在 MBG 中也并不直接支持。一般來說,這兩種查詢都需要你在 Mapper 的 xml 文件中自定義 SQL 來實現(xiàn)。當然,你也可以選擇使用基于注解的方式。這在高級查詢一文中我們已經進行過講解,忘記的回去復習以下即可。
到此這篇關于MyBatis Generator介紹及使用方法的文章就介紹到這了,更多相關MyBatis Generator內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- Mybatis generator修改Mapper.java文件實現(xiàn)詳解
- MyBatis?Generator?ORM層面的代碼自動生成器(推薦)
- 更簡單更高效的Mybatis?Plus最新代碼生成器AutoGenerator
- MybatisX-Generator自動代碼生成插件教程
- Mybatis代碼生成器Mybatis Generator(MBG)實戰(zhàn)詳解
- MyBatis-Plus中AutoGenerator的使用案例
- Mybatis-plus?代碼生成器?AutoGenerator?的簡介和使用詳解
- Mybatis-Plus開發(fā)提速器generator的使用
- MyBatis Generator配置入門
- mybatis-generator-gui根據(jù)需求改動示例
- MyBatis?Generator使用小結
相關文章
Java使用動態(tài)代理和反射實現(xiàn)字段變更跟蹤的方案
該文章介紹了如何使用Java動態(tài)代理和反射技術來跟蹤記錄對象字段的變更前和變更后的數(shù)據(jù),文章詳細講解了創(chuàng)建變更記錄數(shù)據(jù)結構、變更跟蹤處理器、代理工廠,并通過示例展示了如何使用和運行這個代理,需要的朋友可以參考下2025-12-12
SpringBoot集成免費的EdgeTTS實現(xiàn)文本轉語音
在需要文本轉語音(TTS)的應用場景中(如語音助手、語音通知、內容播報等),Java生態(tài)缺少類似Python生態(tài)的Edge?TTS?客戶端庫,不過沒關系,現(xiàn)在可以通過?UnifiedTTS?提供的?API?來調用免費的?EdgeTTS?能力,本文給大家介紹了SpringBoot集成免費的EdgeTTS實現(xiàn)文本轉語音2025-10-10
dubbo環(huán)境搭建ZooKeeper注冊中心全過程
文章介紹Dubbo環(huán)境搭建,包含ZooKeeper注冊中心的安裝配置(修改數(shù)據(jù)存儲路徑、啟動服務并驗證節(jié)點)和dubbo-admin監(jiān)控中心的部署流程(解壓、打包、運行jar包,需注意Maven版本及zkServer狀態(tài))2025-07-07
使用Springboot實現(xiàn)word在線編輯保存
PageOffice目前支持的Web編程語言及架構有:Java(JSP、SSH、MVC等),ASP.NET(C#、VB.NET、MVC、Razor等),PHP,ASP,本篇文章就帶你使用Springboot整合PageOffice實現(xiàn)word在線編輯保存2021-08-08

