Commit 91f37e756aabd52ae24fb7b2cadf425045748774
1 parent
8b616c31
fix(product): 修复@Select查询JSON字段无法解析的问题
@Select注解不会应用autoResultMap,需手动指定@Results和typeHandler: - ProductSpuMapper: sliderPicUrls字段添加JacksonTypeHandler - ProductSkuMapper: properties字段添加JacksonTypeHandler
Showing
2 changed files
with
18 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 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 7 | 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 | 11 | import java.util.Collection; |
| 13 | 12 | import java.util.List; |
| ... | ... | @@ -15,7 +14,14 @@ import java.util.List; |
| 15 | 14 | @Mapper |
| 16 | 15 | public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { |
| 17 | 16 | |
| 17 | + /** | |
| 18 | + * 查询商品 SKU(包含已删除) | |
| 19 | + * 注意:使用 @Results 手动指定 typeHandler,否则 @Select 不会应用 autoResultMap,properties 字段无法解析 JSON | |
| 20 | + */ | |
| 18 | 21 | @Select("SELECT * FROM product_sku WHERE id = #{id}") |
| 22 | + @Results({ | |
| 23 | + @Result(column = "properties", property = "properties", typeHandler = JacksonTypeHandler.class), | |
| 24 | + }) | |
| 19 | 25 | ProductSkuDO selectByIdIncludeDeleted(@Param("id") Long id); |
| 20 | 26 | |
| 21 | 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
| ... | ... | @@ -10,9 +10,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 10 | 10 | import cn.iocoder.yudao.module.product.enums.ProductConstants; |
| 11 | 11 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 12 | 12 | 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; | |
| 13 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 14 | +import org.apache.ibatis.annotations.*; | |
| 16 | 15 | |
| 17 | 16 | import java.util.Objects; |
| 18 | 17 | import java.util.Set; |
| ... | ... | @@ -20,7 +19,14 @@ import java.util.Set; |
| 20 | 19 | @Mapper |
| 21 | 20 | public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { |
| 22 | 21 | |
| 22 | + /** | |
| 23 | + * 查询商品 SPU(包含已删除) | |
| 24 | + * 注意:使用 @Results 手动指定 typeHandler,否则 @Select 不会应用 autoResultMap,sliderPicUrls 字段无法解析 JSON | |
| 25 | + */ | |
| 23 | 26 | @Select("SELECT * FROM product_spu WHERE id = #{id}") |
| 27 | + @Results({ | |
| 28 | + @Result(column = "slider_pic_urls", property = "sliderPicUrls", typeHandler = JacksonTypeHandler.class), | |
| 29 | + }) | |
| 24 | 30 | ProductSpuDO selectByIdIncludeDeleted(@Param("id") Long id); |
| 25 | 31 | |
| 26 | 32 | /** | ... | ... |