商户服务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进行测试



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

被折叠的 条评论
为什么被折叠?



