Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL使用jsonb查询,会把::jsonb变成参数 #30

Closed
mengpp-0001 opened this issue Apr 14, 2022 · 3 comments
Closed

PostgreSQL使用jsonb查询,会把::jsonb变成参数 #30

mengpp-0001 opened this issue Apr 14, 2022 · 3 comments
Milestone

Comments

@mengpp-0001
Copy link

sql字段是下面这个样子
t2.task_item_subjoin::jsonb->> 'pointName'
但我在bean里面这样定义,会给转成 t2.task_item_subjoin ?->> 'pointName'

@troyzhxu
Copy link
Owner

troyzhxu commented Apr 14, 2022

下个版本 在参数解析时 将会忽略 连续的冒号,并添加字符转义功能。

当前版本有两种临时解决方法:

方法一

重写 DefaultSnippetResolver,忽略连续的冒号:

@Bean
public SnippetResolver mySnippetResolver() {
    return new DefaultSnippetResolver() {
        @Override
        public SqlSnippet resolve(String fragment) {
            SqlSnippet snippet = super.resolve(fragment.replace("::", "__"));
            snippet.setSql(snippet.getSql().replace("__", "::"));
            return snippet;
        }
    };
}

方法二

重新定义 Bean Searcher 的嵌入参数前缀,比如将它修改为 $

@Bean
public SnippetResolver mySnippetResolver() {
    DefaultSnippetResolver resolver = new DefaultSnippetResolver();
    resolver.setParamPrefix("$");
    return resolver;
}

如果项目中已经有用嵌入参数,使用这种方法需要 修改以前的实体类,要把嵌入参数的 : 修改为 $

@mengpp-0001
Copy link
Author

已解决,感谢

下个版本 在参数解析时 将会忽略 连续的冒号,并添加字符转义功能。

当前版本有两种临时解决方法:

方法一

重写 ,忽略连续的冒号:DefaultSnippetResolver

@Bean
public SnippetResolver mySnippetResolver() {
    return new DefaultSnippetResolver() {
        @Override
        public SqlSnippet resolve(String fragment) {
            SqlSnippet snippet = super.resolve(fragment.replace("::", "__"));
            snippet.setSql(snippet.getSql().replace("__", "::"));
            return snippet;
        }
    };
}

方法二

重新定义 Bean Searcher 的嵌入参数前缀,比如将它修改为 :$

@Bean
public SnippetResolver mySnippetResolver() {
    DefaultSnippetResolver resolver = new DefaultSnippetResolver();
    resolver.setParamPrefix("$");
    return resolver;
}

如果项目中已经有用嵌入参数,使用这种方法需要 修改以前的实体类,要把嵌入参数的 修改为:``$

@troyzhxu troyzhxu added this to the v2.6.0 milestone Apr 18, 2022
@troyzhxu
Copy link
Owner

troyzhxu commented Apr 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants