From 24207fdc79b87cd24c74ad7d6ee5d6cadfdaf122 Mon Sep 17 00:00:00 2001 From: "jihuan.yin" Date: Mon, 16 May 2022 22:58:49 +0800 Subject: [PATCH] =?UTF-8?q?mybatis=20ognl=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fox-mock-agent/pom.xml | 4 ++- .../agent/transformer/MethodInvokeFilter.java | 10 ++++--- .../cxytiandi/foxmock/example/FoxMockApp.java | 2 ++ .../foxmock/example/mybatis/UserMapper.java | 3 +++ .../foxmock/example/mybatis/UserQuery.java | 26 +++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserQuery.java diff --git a/fox-mock-agent/pom.xml b/fox-mock-agent/pom.xml index 139dc61..8efd75d 100644 --- a/fox-mock-agent/pom.xml +++ b/fox-mock-agent/pom.xml @@ -59,7 +59,10 @@ org.mybatis mybatis + provided + true + @@ -125,7 +128,6 @@ ch.qos.logback:logback-core com.alibaba.arthas:arthas-repackage-logger ognl:ognl - org.mybatis:mybatis diff --git a/fox-mock-agent/src/main/java/com/cxytiandi/foxmock/agent/transformer/MethodInvokeFilter.java b/fox-mock-agent/src/main/java/com/cxytiandi/foxmock/agent/transformer/MethodInvokeFilter.java index ff1f2af..613582b 100644 --- a/fox-mock-agent/src/main/java/com/cxytiandi/foxmock/agent/transformer/MethodInvokeFilter.java +++ b/fox-mock-agent/src/main/java/com/cxytiandi/foxmock/agent/transformer/MethodInvokeFilter.java @@ -95,9 +95,13 @@ private static Object filterAndConvertData(Object[] args) { List parameterMappings = boundSql.getParameterMappings(); for (ParameterMapping mapping : parameterMappings) { - HashMap parameterMap = (HashMap) parameterObject; - Object value = parameterMap.get(mapping.getProperty()); - argsList.add(value); + if (parameterObject instanceof HashMap) { + HashMap parameterMap = (HashMap) parameterObject; + Object value = parameterMap.get(mapping.getProperty()); + argsList.add(value); + } else { + argsList.add(parameterObject); + } } MockInfo mockInfo = MockInfoFactory.create(data); diff --git a/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/FoxMockApp.java b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/FoxMockApp.java index cbb14b0..2eeb05c 100644 --- a/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/FoxMockApp.java +++ b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/FoxMockApp.java @@ -1,6 +1,7 @@ package com.cxytiandi.foxmock.example; import com.cxytiandi.foxmock.example.mybatis.UserMapper; +import com.cxytiandi.foxmock.example.mybatis.UserQuery; import com.google.gson.Gson; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -51,6 +52,7 @@ public static void main(String[] args) throws Exception { UserMapper mapper = ApplicationContextHelper.getBean(UserMapper.class); System.out.println("mapper find:" + new Gson().toJson(mapper.find())); + System.out.println("mapper find2:" + new Gson().toJson(mapper.find2(new UserQuery(1)))); System.out.println("mapper findById:" + new Gson().toJson(mapper.findById(1))); System.out.println("mapper findNameById:" + mapper.findNameById(1)); System.out.println("mapper updateNameById:" + mapper.updateNameById(1, "张三")); diff --git a/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserMapper.java b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserMapper.java index 54ab44a..12a45f2 100644 --- a/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserMapper.java +++ b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserMapper.java @@ -20,4 +20,7 @@ public interface UserMapper { @Update("update t_user set name = #{name} where id = #{id}") int updateNameById(@Param("id") Integer id, @Param("name") String name); + @Select("select * from t_user where id = #{id}") + List find2(UserQuery query); + } diff --git a/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserQuery.java b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserQuery.java new file mode 100644 index 0000000..7c50ce7 --- /dev/null +++ b/fox-mock-example/src/main/java/com/cxytiandi/foxmock/example/mybatis/UserQuery.java @@ -0,0 +1,26 @@ +package com.cxytiandi.foxmock.example.mybatis; + +/** + * @作者 尹吉欢 + * @个人微信 jihuan900 + * @微信公众号 猿天地 + * @GitHub https://github.com/yinjihuan + * @作者介绍 http://cxytiandi.com/about + * @时间 2022-05-16 22:32 + */ +public class UserQuery { + + private Integer id; + + public UserQuery(Integer id) { + this.id = id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId() { + return id; + } +}