admineShopController
@RestController("admineShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {//设置一个常量 因为经常使用public static final String KEY = "SHOP-STATUS";@Autowiredprivate RedisTemplate redisTemplate;/*** 设置店铺营业状态* @param status* @return*/@PutMapping("/{status}")
@ApiOperation("设置店铺营业状态")//路径参数public Result setStatus(@PathVariable Integer status) {log.info("设置营业状态为: {}",status ==1? "营业中": "打样中");redisTemplate.opsForValue().set(KEY, status);return Result.success();}/*** 获取店铺的营业状态* @return*/@GetMapping("/status")@ApiOperation("获取店铺的营业状态")public Result<Integer> getStatus() {Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("获得到店铺的营业状态为:{}",status==1?"营业中":"打样中");return Result.success(status);}}
userShopController
@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {public static final String KEY = "SHOP-STATUS";@Autowiredprivate RedisTemplate redisTemplate;/*** 获取店铺的营业状态* @return*/@GetMapping("/status")@ApiOperation("获取店铺的营业状态")public Result<Integer> getStatus() {Integer status = (Integer) redisTemplate.opsForValue().get(KEY);log.info("获得到店铺的营业状态为:{}",status==1 ?"营业中":"打样中");return Result.success(status);}}
通过knife4j生成接口文档
@Bean
public Docket docket1() {ApiInfo apiInfo = new ApiInfoBuilder().title("苍穹外卖项目接口文档").version("2.0").description("苍穹外卖项目接口文档").build();Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("管理端接口").apiInfo(apiInfo).select()//扫描包.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin")).paths(PathSelectors.any()).build();return docket;
}
@Bean
public Docket docket2() {ApiInfo apiInfo = new ApiInfoBuilder().title("苍穹外卖项目接口文档").version("2.0").description("苍穹外卖项目接口文档").build();Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("用户端接口").apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage("com.sky.controller.user")).paths(PathSelectors.any()).build();return docket;
}