SpringBoot +MyBatis 一个单个id,一个id集合查询查询

SpringBoot +MyBatis 一个单个id,一个id集合查询查询

废话不多说,代码走起来!

请求参数

 {
      	"typeId":2,
    	"thirdLevelId":[1,2,3]
 }

响应参数

{
    "respCode": "200",
    "respMessage": "查询成功",
    "data": [
        {
            "id": 2,
            "feePoints": 6.00,
            "oneCategoryName": "手机",
            "twoCategoryName": "手机配件",
            "threeCategoryName": "移动电源"
        },
        {
            "id": 15,
            "feePoints": 7.00,
            "oneCategoryName": "手机",
            "twoCategoryName": "手机配件",
            "threeCategoryName": "移动电源"
        }
    ]
}

封装的请求参数

public class PointsDTO implements Serializable {
    
   private Integer typeId;

    private Integer[] thirdLevelId;

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public Integer[] getThirdLevelId() {
        return thirdLevelId;
    }

    public void setThirdLevelId(Integer[] thirdLevelId) {
        this.thirdLevelId = thirdLevelId;
    }

}

封装的响应参数

public class PointsVO {
    
    private Integer id;
    private BigDecimal feePoints;
    private String OneCategoryName;
    private String TwoCategoryName;
    private String ThreeCategoryName;

    public PointsVO(Integer id, BigDecimal feePoints, String oneCategoryName, String twoCategoryName, String threeCategoryName) {
        this.id = id;
        this.feePoints = feePoints;
        OneCategoryName = oneCategoryName;
        TwoCategoryName = twoCategoryName;
        ThreeCategoryName = threeCategoryName;
    }

    public PointsVO() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public BigDecimal getFeePoints() {
        return feePoints;
    }

    public void setFeePoints(BigDecimal feePoints) {
        this.feePoints = feePoints;
    }

    public String getOneCategoryName() {
        return OneCategoryName;
    }

    public void setOneCategoryName(String oneCategoryName) {
        OneCategoryName = oneCategoryName;
    }

    public String getTwoCategoryName() {
        return TwoCategoryName;
    }

    public void setTwoCategoryName(String twoCategoryName) {
        TwoCategoryName = twoCategoryName;
    }

    public String getThreeCategoryName() {
        return ThreeCategoryName;
    }

    public void setThreeCategoryName(String threeCategoryName) {
        ThreeCategoryName = threeCategoryName;
    }
}

Mapper接口

List<PointsVO> getAllPointsById(@Param("thirdLevelId") Integer[] thirdLevelId,@Param("typeId") Integer typeId);

Mapper.xml 文件

<select id="getAllPointsById" resultType="com.dy.mallConfig.pojo.vo.PointsVO">
        SELECT
        	points.id AS id,
        	points.fee_points AS feePoints,
        	`third`.category_name AS threeCategoryName,
        	`second`.category_name AS twoCategoryName,
        	`first`.category_name AS oneCategoryName
        FROM
        	category_fee_points points
        LEFT JOIN category_third_level `third` ON `third`.third_level_id = points.third_level_id
        LEFT JOIN category_second_level `second` ON `second`.second_level_id = `third`.parent_id
        LEFT JOIN category_first_level `first` ON `first`.first_level_id = `third`.first_level_id
        where points.type_id=#{typeId}
        AND points.third_level_id IN
        <foreach collection="thirdLevelId" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

Service接口

OutputObject getAllPointsById(PointsDTO pointsDTO);

ServiceImpl实现类

@Override
    public OutputObject getAllPointsById(PointsDTO pointsDTO) {
        try{
            List<PointsVO> list = categoryFeePointsMapper.getAllPointsById(pointsDTO.getThirdLevelId(),pointsDTO.getTypeId());
            return new OutputObject(ReturnCode.SUCCESS,"查询成功",list);
        }catch (Exception e){
            return new OutputObject(ReturnCode.FAIL, "查询失败", e.getMessage());
        }
    }

Controller控制器

 	@PostMapping("/getAllPointsById")
    @ResponseBody
    public OutputObject getAllPointsById(@RequestBody PointsDTO pointsDTO){
        LOGGER.info("com.dy.mallConfig.controller.CategoryFeePointsController.getAllPointsById.对外  根据店铺类型和三级类目查询扣点 PointsDTO",pointsDTO);
        return categoryFeePointsService.getAllPointsById(pointsDTO);
    }

大功告成!!!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值