|
@@ -0,0 +1,23 @@
|
|
|
+package com.nokia.financeapi.config;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.executor.Executor;
|
|
|
+import org.apache.ibatis.mapping.BoundSql;
|
|
|
+import org.apache.ibatis.mapping.MappedStatement;
|
|
|
+import org.apache.ibatis.session.ResultHandler;
|
|
|
+import org.apache.ibatis.session.RowBounds;
|
|
|
+
|
|
|
+public class DescNullsLastInterceptor implements InnerInterceptor {
|
|
|
+ @Override
|
|
|
+ public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds,
|
|
|
+ ResultHandler resultHandler, BoundSql boundSql) {
|
|
|
+ String sql = boundSql.getSql();
|
|
|
+ if (!StringUtils.containsIgnoreCase(sql, "desc")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String sqlNew = sql.replaceAll("(?i)(\\bdesc\\b(?!\\s+nulls\\s+last\\b))(?=[^a-z]|$)", "$1 nulls last");
|
|
|
+ PluginUtils.mpBoundSql(boundSql).sql(sqlNew);
|
|
|
+ }
|
|
|
+}
|