|
24 | 24 | import java.io.Reader;
|
25 | 25 | import java.lang.reflect.Method;
|
26 | 26 | import java.util.ArrayList;
|
| 27 | +import java.util.Collections; |
27 | 28 | import java.util.HashMap;
|
28 | 29 | import java.util.List;
|
29 | 30 | import java.util.Map;
|
|
32 | 33 | import org.apache.ibatis.annotations.DeleteProvider;
|
33 | 34 | import org.apache.ibatis.annotations.Param;
|
34 | 35 | import org.apache.ibatis.annotations.SelectProvider;
|
| 36 | +import org.apache.ibatis.binding.MapperMethod; |
35 | 37 | import org.apache.ibatis.builder.BuilderException;
|
36 | 38 | import org.apache.ibatis.builder.annotation.ProviderContext;
|
37 | 39 | import org.apache.ibatis.builder.annotation.ProviderSqlSource;
|
@@ -619,6 +621,33 @@ void staticMethodOneArgumentAndProviderContext() {
|
619 | 621 | }
|
620 | 622 | }
|
621 | 623 |
|
| 624 | + @Test |
| 625 | + void mapAndProviderContext() { |
| 626 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 627 | + StaticMethodSqlProviderMapper mapper = |
| 628 | + sqlSession.getMapper(StaticMethodSqlProviderMapper.class); |
| 629 | + assertEquals("mybatis", mapper.mapAndProviderContext("mybatis")); |
| 630 | + } |
| 631 | + } |
| 632 | + |
| 633 | + @Test |
| 634 | + void multipleMap() { |
| 635 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 636 | + StaticMethodSqlProviderMapper mapper = |
| 637 | + sqlSession.getMapper(StaticMethodSqlProviderMapper.class); |
| 638 | + assertEquals("123456", mapper.multipleMap(Collections.singletonMap("value", "123"), Collections.singletonMap("value", "456"))); |
| 639 | + } |
| 640 | + } |
| 641 | + |
| 642 | + @Test |
| 643 | + void providerContextAndMap() { |
| 644 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 645 | + StaticMethodSqlProviderMapper mapper = |
| 646 | + sqlSession.getMapper(StaticMethodSqlProviderMapper.class); |
| 647 | + assertEquals("mybatis", mapper.providerContextAndParamMap("mybatis")); |
| 648 | + } |
| 649 | + } |
| 650 | + |
622 | 651 | public interface ErrorMapper {
|
623 | 652 | @SelectProvider(type = ErrorSqlBuilder.class, method = "methodNotFound")
|
624 | 653 | void methodNotFound();
|
@@ -716,6 +745,15 @@ public interface StaticMethodSqlProviderMapper {
|
716 | 745 | @SelectProvider(type = SqlProvider.class, method = "oneArgumentAndProviderContext")
|
717 | 746 | String oneArgumentAndProviderContext(Integer value);
|
718 | 747 |
|
| 748 | + @SelectProvider(type = SqlProvider.class, method = "mapAndProviderContext") |
| 749 | + String mapAndProviderContext(@Param("value") String value); |
| 750 | + |
| 751 | + @SelectProvider(type = SqlProvider.class, method = "providerContextAndParamMap") |
| 752 | + String providerContextAndParamMap(@Param("value") String value); |
| 753 | + |
| 754 | + @SelectProvider(type = SqlProvider.class, method = "multipleMap") |
| 755 | + String multipleMap(@Param("map1") Map<String, Object> map1, @Param("map2") Map<String, Object> map2); |
| 756 | + |
719 | 757 | @SuppressWarnings("unused")
|
720 | 758 | class SqlProvider {
|
721 | 759 |
|
@@ -793,6 +831,18 @@ public static String oneArgumentAndProviderContext(Integer value, ProviderContex
|
793 | 831 | + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS";
|
794 | 832 | }
|
795 | 833 |
|
| 834 | + public static String mapAndProviderContext(Map<String, Object> map, ProviderContext context) { |
| 835 | + return "SELECT '" + map.get("value") + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
| 836 | + } |
| 837 | + |
| 838 | + public static String providerContextAndParamMap(ProviderContext context, MapperMethod.ParamMap<Object> map) { |
| 839 | + return "SELECT '" + map.get("value") + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
| 840 | + } |
| 841 | + |
| 842 | + public static String multipleMap(@Param("map1") Map<String, Object> map1, @Param("map2") Map<String, Object> map2) { |
| 843 | + return "SELECT '" + map1.get("value") + map2.get("value") + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
| 844 | + } |
| 845 | + |
796 | 846 | }
|
797 | 847 |
|
798 | 848 | }
|
|
0 commit comments