哈喽,大家好,我今天又来记录一下鄙人做后端开发的后知后觉:
@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,而且平时在写代码的时候敲回车时也一定要注意,一定要注意,一定要注意引入的包,重要的事情要说三遍!!!!!!