:MAX OR ID<:MIN)} AND NAME IS NOT NULL ${AND LVL"/>

自定义SQL忽略未赋值部分查询条件

最后更新:2024-09-11 05:30:01 | 状态:未完成
在执行查询时,如果有部分占位符没有赋值通常需要忽略这部分条件(XML中定义的SQL及查询条件按相同规则处理)
        String sql = "SELECT * FROM FI_USER WHERE 1=1 ${AND (ID>:MAX OR ID<:MIN)} AND NAME IS NOT NULL ${AND LVL > :LVL} AND LVL < 20";

        // SELECT * FROM FI_USER WHERE NAME IS NOT NULL AND LVL < 20
        ServiceProxy.querys(sql);

        // SELECT * FROM FI_USER WHERE (ID>? OR ID<?) AND NAME IS NOT NULL AND LVL > ? AND LVL < 20
        ServiceProxy.querys(sql, "MAX:1", "MIN:10", "LVL:20");

        // SELECT * FROM FI_USER WHERE NAME IS NOT NULL AND LVL > ? AND LVL < 20
        // ${}中有一个变量未赋值就忽略
        ServiceProxy.querys(sql, "MAX:1", "LVL:30");

首页 最近更新 搜索 提交 回复