美文网首页
解决问题:There is no getter for prop

解决问题:There is no getter for prop

作者: iNick | 来源:发表于2018-11-30 15:38 被阅读0次

# 问题的由来

在早上打开项目想进行继续编写前面没有修改完的多条件查询,
但是在 Service 层将 list 数据传送到 Dao 层进行查询时,突然报错了

There is no getter for property named '__frch_item_0' in class...

在一番查错之后,我觉得应该是我的 XML 文件出错了.
我项目持久层使用的是 MyBatis ,
当时我的 XML 文件是这么写的 :

<foreach collection="selectIds" index="index" item="item" open="(" separator="," close=")" >
    #{item}
</foreach>

没发现哪里不对啊,太神奇,然后去百度上趴了好久,
好像发现了问题.

# 问题解决

原来在 MyBatis 里面的 XML 文件中,
我们需要使用 in 来查询时,是需要进行一些改变的,
不能直接将值塞过去,需要进行遍历,一个一个的放进去

然后在遍历取出 list 的数据时,
不能使用 "#", 而是用 "$",进行取出里面的项,
或者直接使用 index 来进行取出数据
因此我将 XML 文件改成了这样子

<foreach collection="selectIds" index="index" item="item" open="(" separator="," close=")" >
    #{selectIds[${index}]}
</foreach>

此外,还可以使用下面这种方式

<foreach collection="selectIds" index="index" item="item" open="(" separator="," close=")">
    ${item}
</foreach>
  • 先到这里了,欢迎大家多多指教~

相关文章

网友评论

      本文标题:解决问题:There is no getter for prop

      本文链接:https://www.haomeiwen.com/subject/ezufcqtx.html