异常描述
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\-6-1以前的文件\常用项目\GMALL\GMALL-product\target\classes\mapper\gmallproduct\SkuSaleAttrValueDao.xml]The error may involve com.example.gmallproduct.dao.SkuSaleAttrValueDao.itemListThe error occurred while handling resultsSQL: 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@ToStringpublic class SkuItemSaleAttrVo {private Long attrId;private String attrName;private List<AttrValueWithSkuIdVO> attrValues;}@Datapublic class AttrValueWithSkuIdVO {private String attrValue;private String skuIds;}