异常描述

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

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐