Commit 26237ee8dac0da14ab2d2e630e828feabebc1eb3
Committed by
Gitee
!1472 fix(product): 修复@Select查询JSON字段无法解析的问题
Merge pull request !1472 from 大方/fix/product-mapper-json-typehandler
Showing
2 changed files
with
20 additions
and
6 deletions
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java
| @@ -5,9 +5,8 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | @@ -5,9 +5,8 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 7 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 7 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 8 | -import org.apache.ibatis.annotations.Mapper; | ||
| 9 | -import org.apache.ibatis.annotations.Param; | ||
| 10 | -import org.apache.ibatis.annotations.Select; | 8 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; |
| 9 | +import org.apache.ibatis.annotations.*; | ||
| 11 | 10 | ||
| 12 | import java.util.Collection; | 11 | import java.util.Collection; |
| 13 | import java.util.List; | 12 | import java.util.List; |
| @@ -15,7 +14,14 @@ import java.util.List; | @@ -15,7 +14,14 @@ import java.util.List; | ||
| 15 | @Mapper | 14 | @Mapper |
| 16 | public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | 15 | public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { |
| 17 | 16 | ||
| 17 | + /** | ||
| 18 | + * 查询商品 SKU(包含已删除) | ||
| 19 | + * 注意:使用 @Results 手动指定 typeHandler,否则 @Select 不会应用 autoResultMap,properties 字段无法解析 JSON | ||
| 20 | + */ | ||
| 18 | @Select("SELECT * FROM product_sku WHERE id = #{id}") | 21 | @Select("SELECT * FROM product_sku WHERE id = #{id}") |
| 22 | + @Results({ | ||
| 23 | + @Result(column = "properties", property = "properties", typeHandler = JacksonTypeHandler.class), | ||
| 24 | + }) | ||
| 19 | ProductSkuDO selectByIdIncludeDeleted(@Param("id") Long id); | 25 | ProductSkuDO selectByIdIncludeDeleted(@Param("id") Long id); |
| 20 | 26 | ||
| 21 | default List<ProductSkuDO> selectListBySpuId(Long spuId) { | 27 | default List<ProductSkuDO> selectListBySpuId(Long spuId) { |
yudao-module-mall/yudao-module-product/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
| @@ -4,15 +4,15 @@ import cn.hutool.core.util.ObjectUtil; | @@ -4,15 +4,15 @@ import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.type.IntegerListTypeHandler; | ||
| 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; |
| 9 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 10 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 10 | import cn.iocoder.yudao.module.product.enums.ProductConstants; | 11 | import cn.iocoder.yudao.module.product.enums.ProductConstants; |
| 11 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | 12 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 12 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 13 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 13 | -import org.apache.ibatis.annotations.Mapper; | ||
| 14 | -import org.apache.ibatis.annotations.Param; | ||
| 15 | -import org.apache.ibatis.annotations.Select; | 14 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; |
| 15 | +import org.apache.ibatis.annotations.*; | ||
| 16 | 16 | ||
| 17 | import java.util.Objects; | 17 | import java.util.Objects; |
| 18 | import java.util.Set; | 18 | import java.util.Set; |
| @@ -20,7 +20,15 @@ import java.util.Set; | @@ -20,7 +20,15 @@ import java.util.Set; | ||
| 20 | @Mapper | 20 | @Mapper |
| 21 | public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { | 21 | public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { |
| 22 | 22 | ||
| 23 | + /** | ||
| 24 | + * 查询商品 SPU(包含已删除) | ||
| 25 | + * 注意:使用 @Results 手动指定 typeHandler,否则 @Select 不会应用 autoResultMap,sliderPicUrls,deliveryTypes 字段无法解析 JSON | ||
| 26 | + */ | ||
| 23 | @Select("SELECT * FROM product_spu WHERE id = #{id}") | 27 | @Select("SELECT * FROM product_spu WHERE id = #{id}") |
| 28 | + @Results({ | ||
| 29 | + @Result(column = "slider_pic_urls", property = "sliderPicUrls", typeHandler = JacksonTypeHandler.class), | ||
| 30 | + @Result(column = "delivery_types", property = "deliveryTypes", typeHandler = IntegerListTypeHandler.class), | ||
| 31 | + }) | ||
| 24 | ProductSpuDO selectByIdIncludeDeleted(@Param("id") Long id); | 32 | ProductSpuDO selectByIdIncludeDeleted(@Param("id") Long id); |
| 25 | 33 | ||
| 26 | /** | 34 | /** |