mybatis 拼接sql语句 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'in'. Cause:

时间:2023-01-15 08:41:29

<select id="getUserIn" parameterType="QueryVo" resultMap="userMap">
SELECT
<!-- 引用sql片段 -->
<include refid="user_sql" />
  FROM USER
    <where>
      <!-- 遍历pojo传入的集合

      collection="in"  要遍历pojo对象属性名不能是in 否则报错

      -->
      <foreach collection="ids" item="item" index="index" open="id in(" separator="," close=")">

        #{item}
      </foreach>
    </where>
  </select>

异常信息:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'in'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: in [org.apache.ibatis.ognl.ParseException: Encountered " "in" "in "" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'in'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: in [org.apache.ibatis.ognl.ParseException: Encountered " "in" "in "" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy6.getUserIn(Unknown Source)
at cool.zsn.UserDao.Test.UserDaoTest.getUserIn(UserDaoTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'in'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: in [org.apache.ibatis.ognl.ParseException: Encountered " "in" "in "" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:46)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:43)
at org.apache.ibatis.scripting.xmltags.ForEachSqlNode.apply(ForEachSqlNode.java:55)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:41)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
... 29 more
Caused by: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: in [org.apache.ibatis.ognl.ParseException: Encountered " "in" "in "" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...
]
at org.apache.ibatis.ognl.Ognl.parseExpression(Ognl.java:112)
at org.apache.ibatis.scripting.xmltags.OgnlCache.parseExpression(OgnlCache.java:53)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:44)
... 38 more
Caused by: org.apache.ibatis.ognl.ParseException: Encountered " "in" "in "" at line 1, column 1.
Was expecting one of:
":" ...
"not" ...
"+" ...
"-" ...
"~" ...
"!" ...
"(" ...
"true" ...
"false" ...
"null" ...
"#this" ...
"#root" ...
"#" ...
"[" ...
"{" ...
"@" ...
"new" ...
<IDENT> ...
<DYNAMIC_SUBSCRIPT> ...
"\'" ...
"`" ...
"\"" ...
<INT_LITERAL> ...
<FLT_LITERAL> ...

at org.apache.ibatis.ognl.OgnlParser.generateParseException(OgnlParser.java:3172)
at org.apache.ibatis.ognl.OgnlParser.jj_consume_token(OgnlParser.java:3051)
at org.apache.ibatis.ognl.OgnlParser.unaryExpression(OgnlParser.java:1236)
at org.apache.ibatis.ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
at org.apache.ibatis.ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
at org.apache.ibatis.ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
at org.apache.ibatis.ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
at org.apache.ibatis.ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
at org.apache.ibatis.ognl.OgnlParser.andExpression(OgnlParser.java:352)
at org.apache.ibatis.ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
at org.apache.ibatis.ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
at org.apache.ibatis.ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)
at org.apache.ibatis.ognl.OgnlParser.logicalOrExpression(OgnlParser.java:140)
at org.apache.ibatis.ognl.OgnlParser.conditionalTestExpression(OgnlParser.java:101)
at org.apache.ibatis.ognl.OgnlParser.assignmentExpression(OgnlParser.java:64)
at org.apache.ibatis.ognl.OgnlParser.expression(OgnlParser.java:23)
at org.apache.ibatis.ognl.OgnlParser.topLevelExpression(OgnlParser.java:15)
at org.apache.ibatis.ognl.Ognl.parseExpression(Ognl.java:110)
... 40 more