简单易用的轻量级 ORM 框架 lit-jdbc

码农软件 · 软件分类 · ORM/持久层框架 · 2019-09-22 18:11:24

软件介绍

 lit-jdbc 是一款简单易用的轻量级 ORM 框架。

    <dependency>
        <groupId>com.github.liulus</groupId>
        <artifactId>lit-jdbc</artifactId>
        <version>2.0</version>
    </dependency>

使用 API 的方式构建 SQL , 简单安全, 具体的 SQL 执行器是 spring jdbc

lit-jdbc 可以很简单的和 spring 集成, 只需在配置类上加一个注解  @EnableLitJdbc 即可

    @Configuration
    @EnableLitJdbc
    public class SpringConfig {
        // 其他配置
    }

配置完成后, 就可以在 service 或其他需要的地方注入 JdbcTools 对实体进行操作

基本的增删改 可以查看详细的文档, 这里简单介绍下查询的写法:

简单的查询条件 where 方法是实体的属性, 后面的是条件, sql 的条件都有对应的方法

然后直接调用 list() 获取查询列表, 

还可以使用的方法有 count() 获取计数, single() 获取单条结果

    @Test
    public void testSelect6() {

        // 指定条件 code < ? and price > ? and code in (?, ?, ?), ? 参数即为条件逻辑方法中的值
        List<Goods> goods = jdbcTools.select(Goods.class)
                .where("code").lessThan(1123L)
                .and("price").graterThan(548D)
                .and("code").in(1027L, 1078L, 1094L)
                .list();
    }

还可以指定分页参数获取分页列表

    @Test
    public void testSelect7() {

        // 指定条件 code < ? and ( price < ? or category = ? )  ? 参数即为条件逻辑方法中的值
        List<Goods> goodsList = jdbcTools.select(Goods.class)
                .where("code").lessThan(1123L)
                .and()
                .bracket("price").lessThan(28.8D)
                .or("category").equalsTo("100232")
                .end()
                .page(1, 10)
                .list();

        // 分页信息
        PageInfo pageInfo = ((PageList) goodsList).getPageInfo();
    }

多表关联查询

    @Test
    public void testSelect5() {

        Goods single = jdbcTools.select(Goods.class)
                .join(Supplier.class)
                .additionalField(Supplier.class, "code", "name")
                .alias("supplierCode", "supplierName")
                .on(Goods.class, "supplierCode").equalsTo(Supplier.class, "code")
                .where("goodsId").equalsTo(1203L)
                .single();
    }

本文地址:https://codercto.com/soft/d/15173.html

Agile Web Application Development with Yii 1.1 and PHP5

Agile Web Application Development with Yii 1.1 and PHP5

Jeffrey Winesett / Packt Publishing / 2010-08-27

In order to understand the framework in the context of a real-world application, we need to build something that will more closely resemble the types of applications web developers actually have to bu......一起来看看 《Agile Web Application Development with Yii 1.1 and PHP5》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码