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



1116



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



