Java-springboot基于分布式存储的仿小米卡包优惠券后台系统(三)商户投放系统开发

本文详细介绍了商户服务API的开发过程,包括创建商户信息、构建商户详情及投放优惠券模板等核心功能。通过Spring Boot框架,结合FastJSON进行数据转换,实现RESTful风格的接口设计。同时,文中还涉及了如何在启动类中配置拦截器,对特定路径进行请求拦截。

商户服务controller的开发

package com.hyb.passbook.merchants.controller;

import com.alibaba.fastjson.JSON;
import com.hyb.passbook.merchants.service.IMerchantsService;
import com.hyb.passbook.merchants.vo.CreateMerchantsRequest;
import com.hyb.passbook.merchants.vo.PassTemplate;
import com.hyb.passbook.merchants.vo.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 描述:商户服务controller
 */
@Slf4j
@RestController
@RequestMapping("merchants")
public class MerchantsController {
    @Autowired
    IMerchantsService merchantsService;

    @ResponseBody
    @PostMapping("/create")
    public Response createMerchants(@RequestBody CreateMerchantsRequest request){
        log.info("CreateMerchants : {}", JSON.toJSONString(request));
        return merchantsService.createMerchants(request);
    }

    @ResponseBody
    @GetMapping("/{id}")
    public Response bulidMerchantsInfo(@PathVariable Integer id){
        log.info("bulidMerchantsInfo: {}",id);
        return merchantsService.bulidMerchantsInfoById(id);
    }

    @ResponseBody
    @PostMapping("/drop")
    public Response dropPassTemplate(@RequestBody PassTemplate passTemplate){
        log.info("dropPassTemplate: {}",passTemplate);
        return merchantsService.dropPassTemplate(passTemplate);
    }
}

创建拦截器,/merchants路径进行拦截,在启动类中继承WebMvcConfigurerAdapter

package com.hyb.passbook.merchants;

import com.hyb.passbook.merchants.security.AuthCheckIntercepter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


import javax.annotation.Resource;

@SpringBootApplication
public class MerchantsApplication extends WebMvcConfigurerAdapter {
    @Resource
    private AuthCheckIntercepter authCheckIntercepter;

    public static void main(String[] args) {
        SpringApplication.run(MerchantsApplication.class, args);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(authCheckIntercepter).addPathPatterns("/merchants/**");
        super.addInterceptors(registry);
    }
}

使用postman进行测试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值