# lzh-1.8-db-spring-boot-starter **Repository Path**: coding_13/lzh-1.8-db-spring-boot-starter ## Basic Information - **Project Name**: lzh-1.8-db-spring-boot-starter - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-15 - **Last Updated**: 2025-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # lzh-1.8-db-spring-boot-starter This is a starter project based on Spring Boot, designed to provide convenient auto-configuration and utility classes for projects using MyBatis Plus and dynamic data sources. It is suitable for scenarios requiring multi-data source switching, automatic field filling, unique ID generation, and more. --- ## Features - **Dynamic Data Source Support**: Provides annotation-based dynamic data source switching via `LzhDynamicDataSourceAutoConfiguration`. - **Auto Fill Functionality**: Supports automatic filling of time, user ID, and other fields during insertions and updates. - **Unique ID Generator**: Provides a millisecond-level unique ID generator based on timestamps. - **Transaction Template**: Encapsulates a dynamic transaction management template, supporting transaction execution on a specified data source. - **Flexible Configuration**: Allows flexible configuration of auto-fill fields, data sources, and other parameters via `application.yml` or `application.properties`. --- ## Quick Start ### 1. Add Dependency Add the following dependency to your `pom.xml` file: ```xml com.lzh lzh-1.8-db-spring-boot-starter 1.0.0 ``` ### 2. Enable Dynamic Data Source (Optional) Add the following annotation to the main application class to enable dynamic data sources: ```java @EnableDynamicDataSource ``` ### 3. Configure Auto Fill Fields (Optional) Configure auto-fill fields in `application.yml`: ```yaml mybatis-plus: auto-fill: enable: true create-time-field: createTime update-time-field: updateTime create-uid-field: createUid update-uid-field: updateUid ``` ### 4. Use Unique ID Generator Inject and use `TimeUniqueIdUtil`: ```java @Autowired private TimeUniqueIdUtil timeUniqueIdUtil; String id = timeUniqueIdUtil.currentTimestampString(true, true); ``` --- ## Usage Examples ### Dynamic Data Source Switching Use the `@DS` annotation to switch data sources: ```java @DS("slave1") public List queryFromSlave() { return userMapper.selectList(null); } ``` ### Auto Fill Time Fields Time fields do not need to be manually set in the entity class; the framework will automatically fill them: ```java public class User { private String createTime; private String updateTime; } ``` ### Execute Dynamic Transaction Use `DynamicTransactionTemplate` to execute a transaction on a specified data source: ```java @Autowired private DynamicTransactionTemplate dynamicTransactionTemplate; public void doInTransaction() { dynamicTransactionTemplate.execute(status -> { // Database operations return null; }, "slave1"); } ``` --- ## Configuration Options | Configuration | Default Value | Description | |---------------|---------------|-------------| | `mybatis-plus.auto-fill.enable` | `true` | Whether to enable auto-fill functionality | | `mybatis-plus.auto-fill.create-time-field` | `createTime` | Creation time field to auto-fill during insertions | | `mybatis-plus.auto-fill.update-time-field` | `updateTime` | Update time field to auto-fill during updates | | `mybatis-plus.auto-fill.create-uid-field` | `createUid` | Creation user ID field to auto-fill during insertions | | `mybatis-plus.auto-fill.update-uid-field` | `updateUid` | Update user ID field to auto-fill during updates | --- ## Contribution Guide Pull requests and issues are welcome. Please follow these guidelines: - Ensure all tests pass before submitting code. - Provide clear reproduction steps and environment details when submitting issues. - Maintain consistent code style and follow Java coding conventions. --- ## License This project is open-sourced under the [MIT License](https://opensource.org/licenses/MIT).