您的位置:首页 > 健康 > 养生 > @Param注解的踩坑,报错:There is no getter for property named ‘dto‘ in ‘class

@Param注解的踩坑,报错:There is no getter for property named ‘dto‘ in ‘class

2024/10/6 18:20:59 来源:https://blog.csdn.net/weixin_57259781/article/details/141434750  浏览:    关键词:@Param注解的踩坑,报错:There is no getter for property named ‘dto‘ in ‘class

哈喽,大家好,我今天又来记录一下鄙人做后端开发的后知后觉:

@Param注解,相信大家都不陌生吧,@Param 注解用于在 Mapper 接口的方法上明确指定参数的名称,比如如下:

    List<oucherOrderVO> listMaterialVoucherOrder(@Param("dto") ReconAndInvoiceQueryDTO dto);

然后在mapper.xml文件中就可以通过dto来引用变量了。

这天在处理代码测试时报错:

exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'dto' in 'class com.je.business.invoice.model.dto.ReconAndInvoiceQueryDTO';cause:ReflectionException,message:There is no getter for property named 'dto' in 'class com.je.business.invoice.model.dto.ReconAndInvoiceQueryDTO'

我在网上搜索了报错原因,都是大批量的说报错类中ReconAndInvoiceQueryDTO 中没有getter方法,或者说自己的lombok和springboot版本不兼容等问题。

接着,我直接在实体类中手动添加了getter方法并加上了lombok的方法如下:

@AllArgsConstructor
@Data
@ApiModel(value = "查询对账单和开票计划的入参")
public class ReconAndInvoiceQueryDTO {@ApiModelProperty(value = "送货单明细主键list")List<String> shippingOrderDetailIdList;@ApiModelProperty(value = "有送货单的采购订单明细主键")List<String> orderEntryIdHasShippingOrder;@ApiModelProperty(value = "只有采购订单的订单明细主键")List<String> onlyOrderEntryIdList;@ApiModelProperty(value = "对账单单号")private String reconclicationCode;@ApiModelProperty(value = "开票计划单号")private String invoiceCode;@ApiModelProperty(value = "开票明细开票日期(start)")private String invoiceDateStart;@ApiModelProperty(value = "开票明细开票日期(end)")private String invoiceDateEnd;@ApiModelProperty(value = "实体发票号")private String invoiceNumber;@ApiModelProperty(value = "红冲实体发票号")private String sapInvoiceCode;public List<String> getShippingOrderDetailIdList() {return shippingOrderDetailIdList;}public List<String> getOrderEntryIdHasShippingOrder() {return orderEntryIdHasShippingOrder;}public List<String> getOnlyOrderEntryIdList() {return onlyOrderEntryIdList;}public String getReconclicationCode() {return reconclicationCode;}public String getInvoiceCode() {return invoiceCode;}public String getInvoiceDateStart() {return invoiceDateStart;}public String getInvoiceDateEnd() {return invoiceDateEnd;}public String getInvoiceNumber() {return invoiceNumber;}public String getSapInvoiceCode() {return sapInvoiceCode;}
}

很遗憾,最终还是不能和程序牵手成功。

后来问同事,同事说可能是我使用的@Param注解引入的包不正确,所以我就去查看了一下,

确实有问题:

错误的引入:

import org.springframework.data.repository.query.Param

正确的引入因该是annotations的包:

import org.apache.ibatis.annotations.Param;

好了,分享就到这里,希望大家都知道这个bug,而且平时在写代码的时候敲回车时也一定要注意,一定要注意,一定要注意引入的包,重要的事情要说三遍!!!!!!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com