|
32 | 32 | import org.apache.ibatis.annotations.DeleteProvider; |
33 | 33 | import org.apache.ibatis.annotations.Param; |
34 | 34 | import org.apache.ibatis.annotations.SelectProvider; |
| 35 | +import org.apache.ibatis.binding.MapperMethod; |
35 | 36 | import org.apache.ibatis.builder.BuilderException; |
36 | 37 | import org.apache.ibatis.builder.annotation.ProviderContext; |
37 | 38 | import org.apache.ibatis.builder.annotation.ProviderSqlSource; |
@@ -619,6 +620,24 @@ void staticMethodOneArgumentAndProviderContext() { |
619 | 620 | } |
620 | 621 | } |
621 | 622 |
|
| 623 | + @Test |
| 624 | + void mapAndProviderContext() { |
| 625 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 626 | + StaticMethodSqlProviderMapper mapper = |
| 627 | + sqlSession.getMapper(StaticMethodSqlProviderMapper.class); |
| 628 | + assertEquals("mybatis", mapper.mapAndProviderContext("mybatis")); |
| 629 | + } |
| 630 | + } |
| 631 | + |
| 632 | + @Test |
| 633 | + void providerContextAndMap() { |
| 634 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
| 635 | + StaticMethodSqlProviderMapper mapper = |
| 636 | + sqlSession.getMapper(StaticMethodSqlProviderMapper.class); |
| 637 | + assertEquals("mybatis", mapper.providerContextAndParamMap("mybatis")); |
| 638 | + } |
| 639 | + } |
| 640 | + |
622 | 641 | public interface ErrorMapper { |
623 | 642 | @SelectProvider(type = ErrorSqlBuilder.class, method = "methodNotFound") |
624 | 643 | void methodNotFound(); |
@@ -716,6 +735,12 @@ public interface StaticMethodSqlProviderMapper { |
716 | 735 | @SelectProvider(type = SqlProvider.class, method = "oneArgumentAndProviderContext") |
717 | 736 | String oneArgumentAndProviderContext(Integer value); |
718 | 737 |
|
| 738 | + @SelectProvider(type = SqlProvider.class, method = "mapAndProviderContext") |
| 739 | + String mapAndProviderContext(@Param("value") String value); |
| 740 | + |
| 741 | + @SelectProvider(type = SqlProvider.class, method = "providerContextAndParamMap") |
| 742 | + String providerContextAndParamMap(@Param("value") String value); |
| 743 | + |
719 | 744 | @SuppressWarnings("unused") |
720 | 745 | class SqlProvider { |
721 | 746 |
|
@@ -793,6 +818,14 @@ public static String oneArgumentAndProviderContext(Integer value, ProviderContex |
793 | 818 | + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
794 | 819 | } |
795 | 820 |
|
| 821 | + public static String mapAndProviderContext(Map<String, Object> map, ProviderContext context) { |
| 822 | + return "SELECT '" + map.get("value") + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
| 823 | + } |
| 824 | + |
| 825 | + public static String providerContextAndParamMap(ProviderContext context, MapperMethod.ParamMap<Object> map) { |
| 826 | + return "SELECT '" + map.get("value") + "' FROM INFORMATION_SCHEMA.SYSTEM_USERS"; |
| 827 | + } |
| 828 | + |
796 | 829 | } |
797 | 830 |
|
798 | 831 | } |
|
0 commit comments