|
23 | 23 | import java.util.ArrayList;
|
24 | 24 | import java.util.Arrays;
|
25 | 25 | import java.util.HashMap;
|
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
26 | 28 |
|
27 | 29 | import org.apache.ibatis.BaseDataTest;
|
28 | 30 | import org.apache.ibatis.io.Resources;
|
@@ -289,6 +291,28 @@ public void shouldIterateOnceForEachItemInCollection() throws Exception {
|
289 | 291 | assertEquals("__frch_item_2", boundSql.getParameterMappings().get(2).getProperty());
|
290 | 292 | }
|
291 | 293 |
|
| 294 | + @Test |
| 295 | + public void shouldPerformStrictMatchOnForEachVariableSubstitution() throws Exception { |
| 296 | + final Map<String, Object> param = new HashMap<String, Object>(); |
| 297 | + final Map<String, String> uuu = new HashMap<String, String>(); |
| 298 | + uuu.put("u", "xyz"); |
| 299 | + List<Bean> uuuu = new ArrayList<Bean>(); |
| 300 | + uuuu.add(new Bean("bean id")); |
| 301 | + param.put("uuu", uuu); |
| 302 | + param.put("uuuu", uuuu); |
| 303 | + DynamicSqlSource source = createDynamicSqlSource( |
| 304 | + new TextSqlNode("INSERT INTO BLOG (ID, NAME, NOTE, COMMENT) VALUES"), |
| 305 | + new ForEachSqlNode(new Configuration(),mixedContents( |
| 306 | + new TextSqlNode("#{uuu.u}, #{u.id}, #{ u,typeHandler=org.apache.ibatis.type.StringTypeHandler}," |
| 307 | + + " #{u:VARCHAR,typeHandler=org.apache.ibatis.type.StringTypeHandler}")), "uuuu", "uu", "u", "(", ")", ",")); |
| 308 | + BoundSql boundSql = source.getBoundSql(param); |
| 309 | + assertEquals(4, boundSql.getParameterMappings().size()); |
| 310 | + assertEquals("uuu.u", boundSql.getParameterMappings().get(0).getProperty()); |
| 311 | + assertEquals("__frch_u_0.id", boundSql.getParameterMappings().get(1).getProperty()); |
| 312 | + assertEquals("__frch_u_0", boundSql.getParameterMappings().get(2).getProperty()); |
| 313 | + assertEquals("__frch_u_0", boundSql.getParameterMappings().get(3).getProperty()); |
| 314 | + } |
| 315 | + |
292 | 316 | private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
|
293 | 317 | createBlogDataSource();
|
294 | 318 | final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
|
|
0 commit comments