Mybatis-There is no getter for property named 'xx' in 'class xx'

2019年10月09日 11:33 · 阅读(733) ·

参考

Mybatis报错:There is no getter for property named ‘xxxx’ in ‘class xxxx

Mybatis异常There is no getter for property named ‘XXX’ in ‘class java.lang.String’

开发环境

名称 版本
操作系统 Windows 10 X64
JDK JDK1.8(jdk-8u151-windows-x64)
IntelliJ IDEA IntelliJ IDEA 2018.3
Maven Maven 3.6.0

问题描述

访问一个接口,报下面的错误

  1. {
  2. "code": 400,
  3. "message": "nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.tencent.blockchain.vo.EinvoiceChartRequestVO'"
  4. }

原因分析

我检查了对应的代码,对比了相关的字段和 sql,都没有错误

接口-IEinvoiceRepository

  1. @Repository
  2. public interface IEinvoiceRepository extends BaseMapper<TbeEinvoiceinfoEntity> {
  3. /**
  4. * 获取电子发票统计信息
  5. * @param param 发票信息统计参数
  6. * @return 发票信息统计结果 List
  7. */
  8. List<EinvoiceChartEntity> getMerchantEinvoiceChartData(EinvoiceChartRequestVO param);
  9. }

返回类-EinvoiceChartEntity

  1. package com.luoma.model.entity;
  2. import com.baomidou.mybatisplus.annotation.TableField;
  3. import lombok.Data;
  4. import lombok.experimental.Accessors;
  5. /**
  6. * 发票信息统计实体
  7. *
  8. * @author: v_hwhao
  9. * @version:
  10. * @date: 2019-09-30 16:54
  11. */
  12. @Data
  13. @Accessors(chain = true )
  14. public class EinvoiceChartEntity {
  15. /**
  16. * 发票数量
  17. */
  18. @TableField("EinvoiceCount")
  19. private String einvoiceCount;
  20. /**
  21. * 发票金额
  22. */
  23. @TableField("EinvoiceAmount")
  24. private String einvoiceAmount;
  25. /**
  26. * 当前月发票合计税额
  27. */
  28. @TableField("CurrentMonthTaxAmount")
  29. private String currentMonthTaxAmount;
  30. /**
  31. * 发票月份
  32. */
  33. @TableField("EinvoiceMonth")
  34. private String einvoiceMonth;
  35. }

参数类-EinvoiceChartRequestVO

  1. package com.luoma.vo;
  2. import com.alibaba.fastjson.annotation.JSONField;
  3. import com.luoma.model.base.SuperEntity;
  4. import io.swagger.annotations.ApiModelProperty;
  5. import lombok.Data;
  6. import lombok.experimental.Accessors;
  7. /**
  8. * 发票信息统计参数类
  9. *
  10. * @author: v_hwhao
  11. * @version:
  12. * @date: 2019-09-30 11:49
  13. */
  14. @Data
  15. @Accessors(chain = true)
  16. public class EinvoiceChartRequestVO {
  17. /**
  18. * 年份
  19. */
  20. @ApiModelProperty("年份")
  21. @JSONField(name = "year")
  22. private Integer year;
  23. /**
  24. * 月份
  25. */
  26. @ApiModelProperty("月份")
  27. @JSONField(name = "month")
  28. private Integer month;
  29. /**
  30. * 企业 Guid
  31. */
  32. @ApiModelProperty("企业 Guid")
  33. @JSONField(name = "merchantGuid")
  34. private String merchantGuid;
  35. }

映射的 xml 文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.luoma.mapper.IEinvoiceRepository">
  4. <select id="getMerchantEinvoiceChartData"
  5. resultType="com.luoma.model.entity.EinvoiceChartEntity"
  6. parameterType="com.luoma.vo.EinvoiceChartRequestVO">
  7. SELECT COUNT(1) AS einvoiceCount,
  8. SUM(EinvoiceAmount) AS einvoiceAmount,
  9. SUM(TotalTaxAmount) as currentMonthTaxAmount,
  10. MONTH(EinvoiceTime) as einvoiceMonth
  11. FROM tbe_einvoiceinfo
  12. WHERE MerchantGuid = #{param.merchantGuid}
  13. AND YEAR(EinvoiceTime) = #{param.year}
  14. AND EinvoiceStatus = 2
  15. AND BillType=0
  16. AND IsDelete = 0
  17. GROUP BY MONTH(EinvoiceTime)
  18. </select>
  19. </mapper>

问题解决

错误的提示是找不到 param 参数,于是我想是否可以在接口的参数显示定义一下,果然加入之后问题解决了

  1. {
  2. "code": 400,
  3. "message": "nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.tencent.blockchain.vo.EinvoiceChartRequestVO'"
  4. }

修改接口-IEinvoiceRepository-参数加入 @Param("param")

  1. @Repository
  2. public interface IEinvoiceRepository extends BaseMapper<TbeEinvoiceinfoEntity> {
  3. /**
  4. * 获取电子发票统计信息
  5. * @param param 发票信息统计参数
  6. * @return 发票信息统计结果 List
  7. */
  8. List<EinvoiceChartEntity> getMerchantEinvoiceChartData(@Param("param") EinvoiceChartRequestVO param);
  9. }