这个问题怎么解决呀

这个问题怎么解决呀

错误信息:


org.apache.ibatis.exceptions.PersistenceException: 

### Error updating database.  Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{__frch_item_0.currentPrice,#{item.discount}.  Check syntax #{property|(expression), var1=value1, var2=value2, ...} 

### The error may exist in goods.xml

### The error may involve goods.batchInsert

### The error occurred while executing an update

### Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{__frch_item_0.currentPrice,#{item.discount}.  Check syntax #{property|(expression), var1=value1, var2=value2, ...} 


at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)

at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)

at com.imooc.mybatis.MyBatisTestor.testBatchInsert(MyBatisTestor.java:375)

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.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Caused by: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{__frch_item_0.currentPrice,#{item.discount}.  Check syntax #{property|(expression), var1=value1, var2=value2, ...} 

at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.parseParameterMapping(SqlSourceBuilder.java:132)

at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping(SqlSourceBuilder.java:72)

at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken(SqlSourceBuilder.java:67)

at org.apache.ibatis.parsing.GenericTokenParser.parse(GenericTokenParser.java:78)

at org.apache.ibatis.builder.SqlSourceBuilder.parse(SqlSourceBuilder.java:45)

at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:42)

at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:297)

at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:41)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)

at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:576)

at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)

at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)

at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)

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.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)

at com.sun.proxy.$Proxy8.update(Unknown Source)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)

... 24 more

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 43

at java.lang.String.charAt(String.java:658)

at org.apache.ibatis.builder.ParameterExpression.trimmedStr(ParameterExpression.java:131)

at org.apache.ibatis.builder.ParameterExpression.option(ParameterExpression.java:124)

at org.apache.ibatis.builder.ParameterExpression.jdbcTypeOpt(ParameterExpression.java:99)

at org.apache.ibatis.builder.ParameterExpression.property(ParameterExpression.java:70)

at org.apache.ibatis.builder.ParameterExpression.parse(ParameterExpression.java:47)

at org.apache.ibatis.builder.ParameterExpression.<init>(ParameterExpression.java:39)

at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.parseParameterMapping(SqlSourceBuilder.java:128)

... 44 more



Process finished with exit code -1


goods.xml:


   <insert id="batchInsert" parameterType="java.util.List">
       insert t_goods(title, sub_title, original_cost, current_price, discount, is_free_delivery,category_id)
       values
       <foreach collection="list" item="item" index="index" separator=",">
           (#{item.title},#{item.subTitle},#{item.originalCost},#{item.currentPrice,#{item.discount},#{item.isFreeDelivery},#{item.categoryId})
       </foreach>

   </insert>


正在回答

登陆购买课程后可参与讨论,去登陆

4回答

同学你好,老师测试执行了testBatchInsert方法,是有对应的占位符的内容,比如:

http://img1.sycdn.imooc.com//climg/5f223a19097e3ff012060101.jpg

视频中老师只是没有向上拖动打开展示,同学可以忽略这个展示的问题哟。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

好帮手慕小班 2020-07-30 10:24:23

同学你好,同学自己解决了问题很棒。

关于同学说的问号,其实这里的问号-->?是表示占位符,在sql中是程序解析中的占位符, 在程序里需要进行设置的参数进行传递的。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 小老哥丶 #1
    那,为什么视频中的老师不会像我一样有问号?
    2020-07-30 10:31:17
提问者 小老哥丶 2020-07-29 19:52:33

为什么我的日志会出来一串问号呀

http://img1.sycdn.imooc.com//climg/5f2162fd09b1b47914110097.jpg

提问者 小老哥丶 2020-07-29 19:50:15

解决了解决了

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师