比如原sql是 "select a.user_id, a.user_name from table_a a where 1=1 and a.filter_Id='111' and a.filter_type='0'" 修改为 "select a.user_name from table_a a where 1=1 and a.filter_Id='111'" 。 可以去掉某个查询字段和条件
I don't know if druid can do this, but at lease you can do it without druid. If you are using Mybatis, you can add a interceptor to get the sql statement to run. Modify this sql with some sql parser framework (like jsqlparser). Then you will get the new sql.
For example, PageHelper use this technique to page
4条答案
按热度按时间wnavrhmk1#
I don't know if druid can do this, but at lease you can do it without druid. If you are using Mybatis, you can add a interceptor to get the sql statement to run. Modify this sql with some sql parser framework (like jsqlparser). Then you will get the new sql.
For example, PageHelper use this technique to page
6yt4nkrj2#
可以的,你要自己不过你要自己解析出
SQLSelectQueryBlock
,然后像下面的代码这样替换,应该条件的替换或去除也有类似这样的方法。你可以解析出原来的查询项,然后去掉你不要的重新设置查询项zu0ti5jz3#
有没有visitor的例子可以参考。上述直接解析的话会有很多嵌套sql的场景考虑不到
f5emj3cl4#
可以使用parer的 visitor 完成修改 https://github.com/alibaba/druid/wiki/Druid_SQL_AST