# springboot-x-example **Repository Path**: techzhi/springboot-x-example ## Basic Information - **Project Name**: springboot-x-example - **Description**: 常见的springboot组件集成测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-07 - **Last Updated**: 2025-09-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Springboot X Example 这里会介绍常见的自研公共模块的集成使用说明。 # tally-common-tidb 本模块提供了完整的TiDB数据源集成功能,支持动态加载、连接池管理、操作工具等特性。 ## 🏗️ 架构设计 ``` tally-common-tidb/ ├── src/main/java/com/nvxclouds/baize/tally/common/tidb/ │ ├── config/ # 配置管理 │ │ └── TiDBConfigManager.java │ ├── pool/ # 连接池管理 │ │ └── TiDBConnectionPoolManager.java │ ├── utils/ # 操作工具类 │ │ └── TiDBOperationUtils.java │ ├── loader/ # 动态加载器 │ │ └── TiDBUtilsLoader.java │ ├── service/ # 统一服务接口 │ │ └── TiDBService.java │ └── model/ # 数据模型 │ ├── TableColumnInfo.java │ ├── QueryRequest.java │ └── BatchRequest.java ├── pom.xml └── README.md ``` ## ⚙️ 配置说明 ### 添加依赖 在需要使用TiDB功能的模块中添加依赖: ```xml com.nvxclouds.baize.tally tally-common-tidb 3.2.0-springboot2-jdk8-SNAPSHOT ``` ## 🚀 快速开始 ### 1. 启用TiDB 修改配置文件application.yaml启用TiDB: ```yaml # TiDB数据源配置 tidb: # 是否开启TiDB enabled: true # 连接信息 config: host: 192.168.50.9 port: 4000 database: jdf username: root password: Root_123 charset: utf8 timezone: Asia/Shanghai # 连接参数 properties: useUnicode: "true" characterEncoding: "utf8" connectionCollation: "utf8_general_ci" useSSL: "false" allowPublicKeyRetrieval: "true" rewriteBatchedStatements: "true" allowMultiQueries: "true" useCompression: "true" # TiDB专用配置 tidb_isolation_read_engines: "tiflash,tikv" tidb_allow_batch_cop: "1" # 连接池配置 pool: maximum-pool-size: 20 minimum-idle: 5 connection-timeout: 30000 idle-timeout: 600000 max-lifetime: 1800000 pool-name: TiDB-HikariCP leak-detection-threshold: 60000 auto-commit: true # 安全配置 security: encrypt-password: true enable-ssl: false validation-timeout: 5000 connection-test-query: "SELECT 1" ``` ### 2. 基本使用 ```java @Autowired private TiDBService tidbService; // 查询数据 List> users = tidbService.query("SELECT * FROM sys_user WHERE status = ?", "0"); // 更新数据 int count = tidbService.update("UPDATE sys_user SET last_login_time = NOW() WHERE user_id = ?", userId); // 批量操作 List batchParams = Arrays.asList( new Object[]{"用户1", 20}, new Object[]{"用户2", 21} ); int[] results = tidbService.batchUpdate("INSERT INTO test_table (name, age) VALUES (?, ?)", batchParams); // 事务操作 String result = tidbService.executeInTransaction(conn -> { // 在事务中执行操作 return "操作成功"; }); ``` ### 3. 表结构操作 ```java // 获取所有表名 List tableNames = tidbService.getAllTableNames(); // 检查表是否存在 boolean exists = tidbService.tableExists("sys_user"); // 获取表结构 List structure = tidbService.getTableStructure("sys_user"); // 获取表行数 long count = tidbService.getTableRowCount("sys_user"); ``` # tally-common-s3 本模块提供了完整的SeaweedFS S3存储集成功能,支持文件上传、下载、删除、预签名URL等操作。 ## 🏗️ 架构设计 ``` tally-common-s3/ ├── src/main/java/com/nvxclouds/baize/tally/s3/ │ ├── config/ # 配置管理 │ │ ├── SeaweedFsS3AutoConfiguration.java │ │ └── SeaweedFsS3Properties.java │ ├── service/ # 核心服务 │ │ └── SeaweedFsS3Service.java │ ├── util/ # 工具类 │ │ └── SeaweedFsS3Util.java │ └── TallyCommonS3Application.java ├── pom.xml └── README.md ``` ## ⚙️ 配置说明 ### 添加依赖 在需要使用SeaweedFS S3功能的模块中添加依赖: ```xml com.nvxclouds.baize.tally tally-common-s3 3.2.0-springboot2-jdk8-SNAPSHOT ``` ## 🚀 快速开始 ### 1. 启用SeaweedFS S3 修改配置文件application.yaml启用SeaweedFS S3: ```yaml # SeaweedFS S3配置 seaweedfs: s3: # 是否启用S3功能 enabled: true # S3访问密钥 access-key: nvx1 # S3秘密密钥 secret-key: nvx1 # 存储桶名称 bucket-name: gongan # SeaweedFS S3端点URL endpoint: http://192.168.60.70:38333 # AWS区域 region: us-east-1 # 是否启用路径样式访问 path-style-access-enabled: true # 连接超时时间(毫秒) connection-timeout: 10000 # 请求超时时间(毫秒) request-timeout: 30000 # 最大连接数 max-connections: 50 ``` ### 2. 服务方式使用 ```java @Autowired private SeaweedFsS3Service seaweedFsS3Service; // 上传文件 PutObjectResult result = seaweedFsS3Service.uploadFile("path/to/file.txt", inputStream, contentLength, "text/plain"); // 上传字节数组 byte[] data = "Hello World".getBytes(); PutObjectResult result2 = seaweedFsS3Service.uploadFile("path/to/file.txt", data, "text/plain"); // 下载文件 S3Object s3Object = seaweedFsS3Service.downloadFile("path/to/file.txt"); InputStream inputStream = s3Object.getObjectContent(); // 获取文件字节数组 byte[] fileData = seaweedFsS3Service.getFileBytes("path/to/file.txt"); // 删除文件 seaweedFsS3Service.deleteFile("path/to/file.txt"); // 检查文件是否存在 boolean exists = seaweedFsS3Service.doesFileExist("path/to/file.txt"); // 列出文件 List files = seaweedFsS3Service.listFiles("path/to/"); // 生成预签名URL Date expiration = new Date(System.currentTimeMillis() + 3600000); // 1小时后过期 URL presignedUrl = seaweedFsS3Service.generatePresignedUrl("path/to/file.txt", expiration); ``` ### 3. 工具类方式使用 ```java // 上传文件 PutObjectResult result = SeaweedFsS3Util.upload("path/to/file.txt", data, "text/plain"); // 下载文件 S3Object s3Object = SeaweedFsS3Util.download("path/to/file.txt"); // 获取文件字节数组 byte[] fileData = SeaweedFsS3Util.getBytes("path/to/file.txt"); // 删除文件 SeaweedFsS3Util.delete("path/to/file.txt"); // 检查文件是否存在 boolean exists = SeaweedFsS3Util.exists("path/to/file.txt"); // 列出文件 List files = SeaweedFsS3Util.list("path/to/"); // 生成预签名URL(默认1小时过期) URL presignedUrl = SeaweedFsS3Util.generatePresignedUrl("path/to/file.txt"); // 复制文件 CopyObjectResult copyResult = SeaweedFsS3Util.copy("source/file.txt", "destination/file.txt"); // 获取文件元数据 ObjectMetadata metadata = SeaweedFsS3Util.getMetadata("path/to/file.txt"); ``` ### 4. 高级功能 ```java // 获取文件元数据 ObjectMetadata metadata = seaweedFsS3Service.getFileMetadata("path/to/file.txt"); long fileSize = metadata.getContentLength(); String contentType = metadata.getContentType(); Date lastModified = metadata.getLastModified(); // 复制文件 CopyObjectResult copyResult = seaweedFsS3Service.copyFile("source/file.txt", "destination/file.txt"); // 获取存储桶名称 String bucketName = seaweedFsS3Service.getBucketName(); // 获取原生S3客户端(用于高级操作) AmazonS3 s3Client = seaweedFsS3Service.getAmazonS3Client(); ```