diff --git a/mybatis-agent/build.gradle b/mybatis-agent/build.gradle index fe8c593..7546050 100644 --- a/mybatis-agent/build.gradle +++ b/mybatis-agent/build.gradle @@ -31,7 +31,7 @@ allprojects { group 'com.plugins.mybatislog.agent' -version '1.0.22' +version '1.0.23' java { sourceCompatibility = "1.8" diff --git a/mybatis-agent/src/main/java/com/plugins/mybaitslog/preAgent.java b/mybatis-agent/src/main/java/com/plugins/mybaitslog/preAgent.java index af3d76c..74017df 100644 --- a/mybatis-agent/src/main/java/com/plugins/mybaitslog/preAgent.java +++ b/mybatis-agent/src/main/java/com/plugins/mybaitslog/preAgent.java @@ -12,7 +12,7 @@ public class preAgent { //JVM 首先尝试在代理类上调用以下方法 public static void premain(String agentArgs, Instrumentation inst) { - final Pair with = Pair.with("Mybatis", "Plugins"); + final Pair with = Pair.with("Start: ", "MyBatis Log EasyPlus"); System.out.println(with.getValue0() + with.getValue1()); final transformer transformer = new transformer(inst); transformer.transform(); diff --git a/mybatis-idea-plugin/build.gradle b/mybatis-idea-plugin/build.gradle index 1c6709a..3e5bc38 100644 --- a/mybatis-idea-plugin/build.gradle +++ b/mybatis-idea-plugin/build.gradle @@ -35,7 +35,7 @@ allprojects { } group 'com.plugins.mybaitslog.idea.plugin' -version '5.0.7' +version '5.0.7.1' dependencies { compileOnly 'org.jetbrains:annotations:24.0.1' diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PluginUtil.java b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PluginUtil.java index 97dcdc3..aa0b95d 100644 --- a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PluginUtil.java +++ b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PluginUtil.java @@ -35,7 +35,7 @@ private static String getJarPathByStartWith() { if ("lib".equals(listFile.getName())) { final File[] fileslib = listFile.listFiles(); for (File file : fileslib) { - if ("mybatis-agent-1.0.22-all.jar".equals(file.getName())) { + if ("mybatis-agent-1.0.23-all.jar".equals(file.getName())) { return file.toPath().toString(); } } diff --git a/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml b/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml index 0145ca2..7abcf40 100644 --- a/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml @@ -4,7 +4,7 @@ linkkou - 5.0.7 + 5.0.7.1 diff --git a/mybatis-plugin/build.gradle b/mybatis-plugin/build.gradle index 19ce00e..0e73a6e 100644 --- a/mybatis-plugin/build.gradle +++ b/mybatis-plugin/build.gradle @@ -30,7 +30,7 @@ allprojects { } group 'com.plugins.mybatislog.plugin' -version '1.0.2' +version '1.0.3' java { sourceCompatibility = "1.8" diff --git a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java index ef5c465..f14fb74 100644 --- a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java +++ b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java @@ -18,6 +18,7 @@ import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; +import org.apache.ibatis.type.JdbcType; import org.javatuples.Pair; import java.lang.reflect.Field; @@ -103,25 +104,30 @@ private Pair getArgs(Invocation invocation) { MetaObject metaObject = configuration.newMetaObject(parameterObject); for (ParameterMapping parameterMapping : parameterMappings) { String propertyName = parameterMapping.getProperty(); + final JdbcType jdbcType = parameterMapping.getJdbcType(); + String jdbcTypename = ""; + if (null != jdbcType) { + jdbcTypename = String.format("\\s*,\\s*jdbcType\\s*=\\s*%s", jdbcType.name()); + } final HashMap stringObjectHashMap = new HashMap<>(); if (metaObject.hasGetter(propertyName)) { Object obj = metaObject.getValue(propertyName); final String parameterValue = getParameterValue(obj); stringObjectHashMap.put(propertyName, parameterValue); keyvalue.add(stringObjectHashMap); - originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", parameterValue); + originalSql = originalSql.replaceFirst("#\\{\\s*" + propertyName + jdbcTypename + "\\s*}", parameterValue); } else if (boundSql.hasAdditionalParameter(propertyName)) { Object obj = boundSql.getAdditionalParameter(propertyName); final String parameterValue = getParameterValue(obj); stringObjectHashMap.put(propertyName, parameterValue); keyvalue.add(stringObjectHashMap); - originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", parameterValue); - } else if (size == 1 && !(parameterObject instanceof Map)) { + originalSql = originalSql.replaceFirst("#\\{\\s*" + propertyName + jdbcTypename + "\\s*}", parameterValue); + } else if (!(parameterObject instanceof Map)) { //单个参数默认组合 final String parameterValue = getParameterValue(metaObject.getOriginalObject()); stringObjectHashMap.put(propertyName, parameterValue); keyvalue.add(stringObjectHashMap); - originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", parameterValue); + originalSql = originalSql.replaceFirst("#\\{\\s*" + propertyName + jdbcTypename + "\\s*}", parameterValue); } } } @@ -192,6 +198,7 @@ private SqlNode getSqlNode(SqlSource sqlSource) { /** * 如果是字符串对象则加上单引号返回,如果是日期则也需要转换成字符串形式,如果是其他则直接转换成字符串返回。 + * todo 需要改进为MyBatis内置的数据解析能力 * * @param obj 对象 * @return String