# Seoitrc **Repository Path**: QQXQQ/Seoitrc ## Basic Information - **Project Name**: Seoitrc - **Description**: Seoitrc - **Primary Language**: Kotlin - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-08-21 - **Last Updated**: 2026-02-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Seoitrc Seoitrc 是一个轻量级的 ORM(对象关系映射)框架,使用 Kotlin 开发,灵感来源于 MyBatis。它允许开发者通过注解方式定义 Mapper 接口,并自动实现数据库操作。 ## 特性 - **注解驱动**:使用 `@Mapper`、`@Table`、`@Field`、`@Select` 等注解定义数据访问层 - **动态代理**:自动为 Mapper 接口生成代理实现 - **轻量级**:核心代码简洁,易于理解和扩展 - **包扫描**:支持自动扫描指定包路径下的 Mapper 接口 ## 快速开始 ### 1. 添加依赖 首先,在 `build.gradle.kts` 中添加项目依赖: ```kotlin dependencies { implementation("com.msw:seoitrc:1.0.0") } ``` ### 2. 定义实体类 使用 `@Table` 注解标记实体类,使用 `@Field` 注解标记数据库字段: ```java @Table public class User { @Field private Long id; @Field private String name; @Field public int age; } ``` ### 3. 定义 Mapper 接口 使用 `@Mapper` 注解标记 Mapper 接口,并使用 `@Select` 注解定义 SQL 查询: ```java @Mapper public interface UserMapper { @Select("SELECT * FROM user WHERE id = #{id}") User selectById(Long id); @Select("SELECT * FROM user") List selectAll(); } ``` ### 4. 初始化并使用 ```kotlin fun main() { // 创建数据源 val dataSource = YourDataSourceImplementation() // 初始化 Seoitrc val seoitrc = Seoitrc(dataSource, listOf("com.example.mapper")) // 获取 Mapper 实例 val userMapper = seoitrc.getContext().getMapper(UserMapper::class.java) // 执行查询 val user = userMapper.selectById(1L) println("User: $user") } ``` ## 注解说明 | 注解 | 目标 | 说明 | |------|------|------| | `@Mapper` | TYPE | 标记接口为 Mapper | | `@Table` | TYPE | 标记类为数据库表 | | `@Field` | FIELD | 标记字段对应数据库列 | | `@Select` | FUNCTION | 定义 SQL SELECT 查询 | ## 项目结构 ``` src/main/kotlin/com/msw/seoitrc/ ├── Seoitrc.kt # 主入口类 ├── annotation/ # 注解定义 │ ├── Field.kt │ ├── Mapper.kt │ ├── Select.kt │ └── Table.kt ├── context/ # 上下文管理 │ ├── MapperContext.kt │ └── SeoitrcContext.kt ├── proxy/ # 动态代理 │ ├── MapperMethod.kt │ └── MapperProxy.kt ├── resolveHandler/ # 实体解析 │ └── EntityResolveHandler.kt └── scan/ # 类扫描 └── ScanClassInPackage.kt ``` ## 贡献指南 欢迎提交 Pull Request 和 Issue! ## 许可证 本项目基于 MIT 许可证开源。