参考
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 |
问题描述
访问一个接口,报下面的错误
{
"code": 400,
"message": "nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.tencent.blockchain.vo.EinvoiceChartRequestVO'"
}
原因分析
我检查了对应的代码,对比了相关的字段和 sql,都没有错误
接口-IEinvoiceRepository
@Repository
public interface IEinvoiceRepository extends BaseMapper<TbeEinvoiceinfoEntity> {
/**
* 获取电子发票统计信息
* @param param 发票信息统计参数
* @return 发票信息统计结果 List
*/
List<EinvoiceChartEntity> getMerchantEinvoiceChartData(EinvoiceChartRequestVO param);
}
返回类-EinvoiceChartEntity
package com.luoma.model.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 发票信息统计实体
*
* @author: v_hwhao
* @version:
* @date: 2019-09-30 16:54
*/
@Data
@Accessors(chain = true )
public class EinvoiceChartEntity {
/**
* 发票数量
*/
@TableField("EinvoiceCount")
private String einvoiceCount;
/**
* 发票金额
*/
@TableField("EinvoiceAmount")
private String einvoiceAmount;
/**
* 当前月发票合计税额
*/
@TableField("CurrentMonthTaxAmount")
private String currentMonthTaxAmount;
/**
* 发票月份
*/
@TableField("EinvoiceMonth")
private String einvoiceMonth;
}
参数类-EinvoiceChartRequestVO
package com.luoma.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.luoma.model.base.SuperEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 发票信息统计参数类
*
* @author: v_hwhao
* @version:
* @date: 2019-09-30 11:49
*/
@Data
@Accessors(chain = true)
public class EinvoiceChartRequestVO {
/**
* 年份
*/
@ApiModelProperty("年份")
@JSONField(name = "year")
private Integer year;
/**
* 月份
*/
@ApiModelProperty("月份")
@JSONField(name = "month")
private Integer month;
/**
* 企业 Guid
*/
@ApiModelProperty("企业 Guid")
@JSONField(name = "merchantGuid")
private String merchantGuid;
}
映射的 xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.luoma.mapper.IEinvoiceRepository">
<select id="getMerchantEinvoiceChartData"
resultType="com.luoma.model.entity.EinvoiceChartEntity"
parameterType="com.luoma.vo.EinvoiceChartRequestVO">
SELECT COUNT(1) AS einvoiceCount,
SUM(EinvoiceAmount) AS einvoiceAmount,
SUM(TotalTaxAmount) as currentMonthTaxAmount,
MONTH(EinvoiceTime) as einvoiceMonth
FROM tbe_einvoiceinfo
WHERE MerchantGuid = #{param.merchantGuid}
AND YEAR(EinvoiceTime) = #{param.year}
AND EinvoiceStatus = 2
AND BillType=0
AND IsDelete = 0
GROUP BY MONTH(EinvoiceTime)
</select>
</mapper>
问题解决
错误的提示是找不到 param
参数,于是我想是否可以在接口的参数显示定义一下,果然加入之后问题解决了
{
"code": 400,
"message": "nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.tencent.blockchain.vo.EinvoiceChartRequestVO'"
}
修改接口-IEinvoiceRepository-参数加入 @Param("param")
@Repository
public interface IEinvoiceRepository extends BaseMapper<TbeEinvoiceinfoEntity> {
/**
* 获取电子发票统计信息
* @param param 发票信息统计参数
* @return 发票信息统计结果 List
*/
List<EinvoiceChartEntity> getMerchantEinvoiceChartData(@Param("param") EinvoiceChartRequestVO param);
}