@Param注解学习


一开始是在mybatis中查询报错:

MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'xxxxx' not found. Available parameters are [payment, page, param1, param2]"

只有在查一个参数的时候报错另一个参数的时候又不会,就很奇怪,后来查看到一篇文章得到启发:

https://blog.csdn.net/zhangvivid/article/details/80990595

 

 

 

 我的接口中有两个参数,然后我就试着加了@Param注解,就真的没有报错了

 

 

这让我想起上几天mybatis中有另一个bug:接口传参为List 时写 <if>标签总是出错,后来也是在传参中加了@Param 才解决的。

 

接口:

List<AttachmentDetail> findFileListByInfoId(@Param("list") List<AttachmentInfo> attachmentInfos);

xml:

<select id="findFileListByInfoId"
resultType="xxx.commonservice.hdfs.entity.AttachmentDetail">
SELECT
det.id,
det.file_name,
det.file_suffix,
det.file_size
FROM
hdfs_attachment_detail det
WHERE 1=1 and
<if test="list != null and list.size() > 0">
det.attachment_info_id in
<foreach item="item" collection="list" separator="," open="(" close=")" index="">#{item.id}
</foreach>
</if>
ORDER BY det.created_date DESC
</select>

总结:

对于mybatis的接口类中的方法,

1.当方法参数数量大于1时,需要在方法参数中使用@Param把函数参数与Mapper.xml文件中的参数关联。

2.接口传参为List时需要使用@Param


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM