异常描述

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
 Error querying database.  Cause: java.lang.NullPointerExceptionThe error may exist in file [E:\IDEA\2022-6-1以前的文件\常用项目\GMALL\GMALL-product\target\classes\mapper\gmallproduct\SkuSaleAttrValueDao.xml]
 The error may involve com.example.gmallproduct.dao.SkuSaleAttrValueDao.itemList
The error occurred while handling results
SQL: SELECT             ssav.attr_id attr_id,             ssav.attr_name attr_name,             ssav.attr_value,             group_concat( DISTINCT info.sku_id ) sku_ids         FROM             pms_sku_info info                 LEFT JOIN pms_sku_sale_attr_value ssav ON ssav.sku_id = info.sku_id         WHERE             info.spu_id = ?         GROUP BY             ssav.attr_id,             ssav.attr_name,             ssav.attr_value;
Cause: java.lang.NullPointerException
问题解决:
问题出在mapper文件的collection集合表述中

原来

<collection property="attrValues">
<result property="attrValue" column="attr_value" javaType="String" jdbcType="VARCHAR"/>
<result property="skuIds" column="sku_id"  javaType="String" jdbcType="BIGINT"/>
</collection>
**改为**

<collection property="attrValues" ofType="com.example.gmallproduct.VO.item.AttrValueWithSkuIdVO">
<result property="attrValue" column="attr_value" javaType="String" jdbcType="VARCHAR"/>
<result property="skuIds" column="sku_id"  javaType="String" jdbcType="BIGINT"/>
</collection>
也就是加上**oftype**
**我的实体类**

@Data
@ToString
public class SkuItemSaleAttrVo {
    private Long attrId;
    private String attrName;
    private List<AttrValueWithSkuIdVO> attrValues;
}
@Data
public class AttrValueWithSkuIdVO {

   private String attrValue;

   private String skuIds;

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐