找回密码
 立即注册
首页 业界区 业界 Kite:Kotlin/Java 通用的全自动 ORM 框架

Kite:Kotlin/Java 通用的全自动 ORM 框架

仰翡邸 2026-1-22 21:20:00
Kite:Kotlin/Java 通用的全自动 ORM 框架

Kite 是一个高效的轻量级 ORM 框架,基于 Kotlin 编写,开箱即用,内置分页查询、增删改查等常用功能,支持多表操作。它支持 PostgreSQL、MySQL、Derby 等多种数据库,旨在通过简化数据库操作,减少代码量,提升开发效率。
框架特点


  • 全自动映射:无需手动编写 SQL,Kite 会自动根据实体类生成相应的数据库操作语句
  • 支持自定义 SQL:在需要时,可以编写自定义 SQL 语句,满足复杂查询需求,还可以像写代码一样写流程控制语句
  • 多数据库支持:支持 PostgreSQL、MySQL、Derby 等主流关系型数据库
  • Kotlin/Java 双语言支持:既可以在 Kotlin 项目中使用,也可以在 Java 项目中无缝集成
  • 轻量级设计:无过多依赖,性能优秀
  • 丰富的 API:提供简洁直观的 API,支持各种复杂查询和操作
  • Spring Boot 集成:提供 Spring Boot Starter,便于在 Spring Boot 项目中快速集成
使用方法(Spring Boot 集成示例)

Maven 中央仓库: kite-spring-boot-starter

  • 向项目添加以下依赖:


  • Maven
  1. <dependency>
  2.    <groupId>io.github.tangllty</groupId>
  3.    kite-spring-boot-starter</artifactId>
  4.    <version>${kite.version}</version>
  5. </dependency>
复制代码

  • Gradle
  1. implementation("io.github.tangllty:kite-spring-boot-starter:${kite.version}")
复制代码

  • 在数据库中创建表
使用 MySQL 演示
  1. create table account (
  2.   id          bigint not null auto_increment,
  3.   username    varchar(32)     default '',
  4.   password    varchar(32)     default '',
  5.   balance     decimal(10,2)   default '0.00',
  6.   create_time datetime        default null,
  7.   update_time datetime        default null,
  8.   primary key (`id`)
  9. );
  10. insert into account (username, password, create_time, balance) values
  11. ('admin', 'admin123', '2020-01-01 12:00:00', 1000.10),
  12. ('user', 'user123', '2024-05-02 8:30:00', 101.00),
  13. ('guest', 'guest123', '2022-03-03 15:00:00', 10.00),
  14. ('tang', 'tang123', '2019-06-01 21:30:30', 1.88),
  15. ('jeo', 'jeo123', '2024-07-01 5:59:59', 0.10);
复制代码

  • 在 application.yml 文件中配置数据库连接信息
  1. spring:
  2.   datasource:
  3.     driver-class-name: com.mysql.cj.jdbc.Driver
  4.     url: jdbc:mysql://127.0.0.1:3306/kite-test
  5.     username: root
  6.     password: password
复制代码

  • 为 account 表创建模型类


  • Java
  1. import com.tang.kite.annotation.id.Id;
  2. import com.tang.kite.annotation.id.IdType;
  3. import java.math.BigDecimal;
  4. import java.time.LocalDateTime;
  5. public class Account {
  6.     @Id(type = IdType.AUTO)
  7.     private Long id;
  8.     private String username;
  9.     private String password;
  10.     private BigDecimal balance;
  11.     private LocalDateTime createTime;
  12.     private LocalDateTime updateTime;
  13.     // Getters and Setters
  14. }
复制代码

  • Kotlin
  1. import com.tang.kite.annotation.id.Id
  2. import com.tang.kite.annotation.id.IdType
  3. import java.math.BigDecimal
  4. import java.time.LocalDateTime
  5. class Account (
  6.     @Id(type = IdType.AUTO)
  7.     var id: Long? = null,
  8.     var username: String? = null,
  9.     var password: String? = null,
  10.     var balance: BigDecimal? = null,
  11.     var createTime: LocalDateTime? = null,
  12.     var updateTime: LocalDateTime? = null
  13. )
复制代码

  • 继承 BaseMapper 接口创建 Mapper 接口


  • Java
  1. import com.tang.kite.mapper.BaseMapper;
  2. import com.tang.kite.spring.annotation.Mapper;
  3. @Mapper
  4. public interface AccountMapper extends BaseMapper {
  5. }
复制代码

  • Kotlin
  1. import com.tang.kite.mapper.BaseMapper
  2. import com.tang.kite.spring.annotation.Mapper
  3. @Mapper
  4. interface AccountMapper : BaseMapper
复制代码

  • 在 Spring Boot 应用类上添加 @MapperScan 注解


  • Java
  1. import com.tang.kite.spring.annotation.MapperScan;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @MapperScan("com.tang.application.mapper")
  5. @SpringBootApplication
  6. public class KiteApplication {
  7.     public static void main(String[] args) {
  8.         SpringApplication.run(KiteApplication.class, args);
  9.     }
  10. }
复制代码

  • Kotlin
  1. import com.tang.kite.spring.annotation.MapperScan
  2. import org.springframework.boot.autoconfigure.SpringBootApplication
  3. import org.springframework.boot.runApplication
  4. @MapperScan(["com.tang.application.mapper"])
  5. @SpringBootApplication
  6. class KiteApplication
  7. fun main(args: Array<String>) {
  8.         runApplication<KiteApplication>(*args)
  9. }
复制代码

  • 测试 Mapper 接口


  • Java
  1. import com.tang.demo.mapper.AccountMapper;
  2. import com.tang.kite.spring.annotation.MapperScan;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. @MapperScan("com.tang.application.mapper")
  6. @SpringBootApplication
  7. public class KiteApplication {
  8.     public static void main(String[] args) {
  9.         var context = SpringApplication.run(KiteApplication.class, args);
  10.         var accountMapper = context.getBean(AccountMapper.class);
  11.         var accounts = accountMapper.select();
  12.         accounts.forEach(System.out::println);
  13.     }
  14. }
复制代码

  • Kotlin
  1. import com.tang.demo.mapper.AccountMapper
  2. import com.tang.kite.spring.annotation.MapperScan
  3. import org.springframework.boot.autoconfigure.SpringBootApplication
  4. import org.springframework.boot.runApplication
  5. @MapperScan(["com.tang.application.mapper"])
  6. @SpringBootApplication
  7. class KiteApplication
  8. fun main(args: Array<String>) {
  9.         val context = runApplication<KiteApplication>(*args)
  10.         val accountMapper = context.getBean(AccountMapper::class.java)
  11.         val accounts = accountMapper.select()
  12.         accounts.forEach { println(it) }
  13. }
复制代码
文档与社区

官方文档

详细的使用文档请参考:

  • 中文文档
  • 英文文档
源码

Kite 的源码托管在 GitHub 和 Gitee 上,您可以在以下地址查看和贡献:

  • Kite GitHub 仓库
  • Kite Gitee 仓库
总结

Kite 是一个功能强大、易于使用的 ORM 框架,它通过全自动映射和简洁的 API,大大简化了数据库操作的开发工作。无论是在 Kotlin 项目还是 Java 项目中,都能提供高效、便捷的数据库访问体验。
如果您正在寻找一个轻量级、高性能的 ORM 框架,Kite 绝对值得一试!

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

2026-1-24 04:33:26

举报

喜欢鼓捣这些软件,现在用得少,谢谢分享!
您需要登录后才可以回帖 登录 | 立即注册