要如何在service_edu中来使用这个service_base呢?

(1)引入依赖文件

在service_edu的pom文件中引入service_base作为依赖(敲service_base即有提示,也可以从service_base的pom文件复制groupId等信息)

<dependency>
       <groupId>com.wangzhou</groupId>
       <artifactId>service_base</artifactId>
       <version>0.0.1-SNAPSHOT</version>
</dependency>

(2)更改文件扫描规则

在service_base中SwaggerConfig是配置类。service_edu在启动时会扫描该模块的文件,然而配置类不在项目service_edu中。我们可以在service_edu的启动类中增加注解@ComponentScan(basePackages = {"com.wangzhou"}),这样所有com.wangzhou包下的文件都可以被扫描到。

现在来测试下。

启动项目,访问http://localhost:8001/swagger-ui.html。出现了一个绿油油的网页。说明swagger已经整合成功了。不过,好像还有一点点小瑕疵。提示"Uable to infer base url".

alt 在启动类添加注解@EnableSwagger2,重启项目,再次访问。漂漂亮亮,干干净净了。

alt 小手点一点。点edu-teacher-controller -> findAll ->try it out.

alt 测试结果出来了。

alt 测试下逻辑删除功能。

alt 查看数据库。成功了。 alt 在controller中removeTeacher()添加注解,可以使生成的文档信息包含注释,方便调试,读者可自行测试。

@ApiOperation("删除讲师")
@DeleteMapping("/deleteTeacherById/{id}")
public boolean removeTeacher(@ApiParam(name = "id", value = "讲师id", required = true) @PathVariable String id) {
     boolean flag= eduTeacherService.removeById(id);
     return flag;
}