傅行帆 6 years ago
parent
commit
77ad245a97

+ 12
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/pom.xml View File

45
 			<artifactId>spring-cloud-starter-openfeign</artifactId>
45
 			<artifactId>spring-cloud-starter-openfeign</artifactId>
46
 		</dependency>
46
 		</dependency>
47
 
47
 
48
+		<dependency>
49
+			<groupId>io.springfox</groupId>
50
+			<artifactId>springfox-swagger2</artifactId>
51
+			<version>2.7.0</version>
52
+		</dependency>
53
+
54
+		<dependency>
55
+			<groupId>io.springfox</groupId>
56
+			<artifactId>springfox-swagger-ui</artifactId>
57
+			<version>2.7.0</version>
58
+		</dependency>
59
+
48
 		<dependency>
60
 		<dependency>
49
 			<groupId>org.mybatis.spring.boot</groupId>
61
 			<groupId>org.mybatis.spring.boot</groupId>
50
 			<artifactId>mybatis-spring-boot-starter</artifactId>
62
 			<artifactId>mybatis-spring-boot-starter</artifactId>

+ 40
- 0
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/Swagger2.java View File

1
+package com.example.demo;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import springfox.documentation.builders.ApiInfoBuilder;
6
+import springfox.documentation.builders.PathSelectors;
7
+import springfox.documentation.builders.RequestHandlerSelectors;
8
+import springfox.documentation.service.ApiInfo;
9
+import springfox.documentation.service.Contact;
10
+import springfox.documentation.spi.DocumentationType;
11
+import springfox.documentation.spring.web.plugins.Docket;
12
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
13
+
14
+/**
15
+ * @author FXF
16
+ * @date 2018-09-27
17
+ */
18
+@Configuration
19
+@EnableSwagger2
20
+public class Swagger2 {
21
+    @Bean
22
+    public Docket docket(){
23
+        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
24
+                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
25
+                .paths(PathSelectors.any()).build();
26
+    }
27
+    //构建api文档的详细信息函数
28
+    private ApiInfo apiInfo(){
29
+        return new ApiInfoBuilder()
30
+                //页面标题
31
+                .title("eureka-client1 的 RESTful API")
32
+                //创建人
33
+                .contact(new Contact("fuxingfan","","fuxingfan@dingtalk.com"))
34
+                //版本号
35
+                .version("1.0")
36
+                //描述
37
+                .description("API 描述")
38
+                .build();
39
+    }
40
+}

+ 10
- 3
SmartCommunity/SmartCommunityV1/eureka-client1/src/main/java/com/example/demo/controller/TestController.java View File

4
 import com.example.demo.model.ScUser;
4
 import com.example.demo.model.ScUser;
5
 import com.example.demo.service.ScUserServiceI;
5
 import com.example.demo.service.ScUserServiceI;
6
 import com.netflix.discovery.DiscoveryClient;
6
 import com.netflix.discovery.DiscoveryClient;
7
+import io.swagger.annotations.Api;
8
+import io.swagger.annotations.ApiImplicitParam;
9
+import io.swagger.annotations.ApiOperation;
7
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.beans.factory.annotation.Value;
11
 import org.springframework.beans.factory.annotation.Value;
9
 import org.springframework.cloud.context.config.annotation.RefreshScope;
12
 import org.springframework.cloud.context.config.annotation.RefreshScope;
10
 import org.springframework.web.bind.annotation.RequestMapping;
13
 import org.springframework.web.bind.annotation.RequestMapping;
14
+import org.springframework.web.bind.annotation.RequestMethod;
11
 import org.springframework.web.bind.annotation.ResponseBody;
15
 import org.springframework.web.bind.annotation.ResponseBody;
12
 import org.springframework.web.bind.annotation.RestController;
16
 import org.springframework.web.bind.annotation.RestController;
13
 
17
 
20
 @RestController
24
 @RestController
21
 @RefreshScope
25
 @RefreshScope
22
 @RequestMapping("/client1")
26
 @RequestMapping("/client1")
27
+@Api("eureka-client1的测试controller的API")
23
 public class TestController {
28
 public class TestController {
24
     
29
     
25
     @Value("${abc}")
30
     @Value("${abc}")
31
     @Autowired
36
     @Autowired
32
     private MicroTestController microTestController;
37
     private MicroTestController microTestController;
33
     
38
     
34
-    @RequestMapping("/hello")
39
+    @ApiOperation(value = "测试无参", notes = "无参")
40
+    @RequestMapping(value = "/hello",method = RequestMethod.GET)
35
     @ResponseBody
41
     @ResponseBody
36
     public String index(){
42
     public String index(){
37
         return abc;
43
         return abc;
41
      * 获取所有的用户信息
47
      * 获取所有的用户信息
42
      * @return
48
      * @return
43
      */
49
      */
44
-    @RequestMapping("/user")
50
+    @ApiOperation(value = "测试restful接口", notes = "测试接口")
51
+    @RequestMapping(value = "/user",method = RequestMethod.GET)
45
     @ResponseBody
52
     @ResponseBody
46
     public List<ScUser> getUser(){
53
     public List<ScUser> getUser(){
47
         return scUserService.getUser();
54
         return scUserService.getUser();
48
     }
55
     }
49
     
56
     
50
-    @RequestMapping("/feignUser")
57
+    @RequestMapping(value = "/feignUser",method = RequestMethod.GET)
51
     @ResponseBody
58
     @ResponseBody
52
     public List<ScUser> getMicroUser(){
59
     public List<ScUser> getMicroUser(){
53
         return microTestController.getUser();
60
         return microTestController.getUser();

+ 12
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/pom.xml View File

39
 			<artifactId>spring-cloud-starter-openfeign</artifactId>
39
 			<artifactId>spring-cloud-starter-openfeign</artifactId>
40
 		</dependency>
40
 		</dependency>
41
 
41
 
42
+		<dependency>
43
+			<groupId>io.springfox</groupId>
44
+			<artifactId>springfox-swagger2</artifactId>
45
+			<version>2.7.0</version>
46
+		</dependency>
47
+
48
+		<dependency>
49
+			<groupId>io.springfox</groupId>
50
+			<artifactId>springfox-swagger-ui</artifactId>
51
+			<version>2.7.0</version>
52
+		</dependency>
53
+
42
 		<dependency>
54
 		<dependency>
43
 			<groupId>org.springframework.cloud</groupId>
55
 			<groupId>org.springframework.cloud</groupId>
44
 			<artifactId>spring-cloud-starter-config</artifactId>
56
 			<artifactId>spring-cloud-starter-config</artifactId>

+ 40
- 0
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/Swagger2.java View File

1
+package com.example.demo;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import springfox.documentation.builders.ApiInfoBuilder;
6
+import springfox.documentation.builders.PathSelectors;
7
+import springfox.documentation.builders.RequestHandlerSelectors;
8
+import springfox.documentation.service.ApiInfo;
9
+import springfox.documentation.service.Contact;
10
+import springfox.documentation.spi.DocumentationType;
11
+import springfox.documentation.spring.web.plugins.Docket;
12
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
13
+
14
+/**
15
+ * @author FXF
16
+ * @date 2018-09-27
17
+ */
18
+@Configuration
19
+@EnableSwagger2
20
+public class Swagger2 {
21
+    @Bean
22
+    public Docket docket(){
23
+        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
24
+                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
25
+                .paths(PathSelectors.any()).build();
26
+    }
27
+    //构建api文档的详细信息函数
28
+    private ApiInfo apiInfo(){
29
+        return new ApiInfoBuilder()
30
+                //页面标题
31
+                .title("eureka-client2 的 RESTful API")
32
+                //创建人
33
+                .contact(new Contact("fuxingfan","","fuxingfan@dingtalk.com"))
34
+                //版本号
35
+                .version("1.0")
36
+                //描述
37
+                .description("API 描述")
38
+                .build();
39
+    }
40
+}

+ 9
- 3
SmartCommunity/SmartCommunityV1/eureka-client2/src/main/java/com/example/demo/controller/TestController.java View File

3
 import com.example.demo.microController.MicroTestController;
3
 import com.example.demo.microController.MicroTestController;
4
 import com.example.demo.model.ScUser;
4
 import com.example.demo.model.ScUser;
5
 import com.example.demo.service.ScUserServiceI;
5
 import com.example.demo.service.ScUserServiceI;
6
+import io.swagger.annotations.Api;
7
+import io.swagger.annotations.ApiOperation;
6
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.beans.factory.annotation.Value;
9
 import org.springframework.beans.factory.annotation.Value;
8
 import org.springframework.cloud.context.config.annotation.RefreshScope;
10
 import org.springframework.cloud.context.config.annotation.RefreshScope;
9
 import org.springframework.web.bind.annotation.RequestMapping;
11
 import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.bind.annotation.RequestMethod;
10
 import org.springframework.web.bind.annotation.ResponseBody;
13
 import org.springframework.web.bind.annotation.ResponseBody;
11
 import org.springframework.web.bind.annotation.RestController;
14
 import org.springframework.web.bind.annotation.RestController;
12
 
15
 
19
 @RestController
22
 @RestController
20
 @RefreshScope
23
 @RefreshScope
21
 @RequestMapping("/client2")
24
 @RequestMapping("/client2")
25
+@Api("eureka-client2的测试controller的API")
22
 public class TestController {
26
 public class TestController {
23
     
27
     
24
     @Value("${abc}")
28
     @Value("${abc}")
30
     @Autowired
34
     @Autowired
31
     private MicroTestController microTestController;
35
     private MicroTestController microTestController;
32
     
36
     
33
-    @RequestMapping("/hello")
37
+    @ApiOperation(value = "测试无参", notes = "无参")
38
+    @RequestMapping(value = "/hello",method = RequestMethod.GET)
34
     @ResponseBody
39
     @ResponseBody
35
     public String index(){
40
     public String index(){
36
         return abc;
41
         return abc;
40
      * 获取所有的用户信息
45
      * 获取所有的用户信息
41
      * @return
46
      * @return
42
      */
47
      */
43
-    @RequestMapping("/user")
48
+    @ApiOperation(value = "测试restful接口", notes = "测试接口2")
49
+    @RequestMapping(value = "/user",method = RequestMethod.GET)
44
     @ResponseBody
50
     @ResponseBody
45
     public List<ScUser> getUser(){
51
     public List<ScUser> getUser(){
46
         return scUserService.getUser();
52
         return scUserService.getUser();
47
     }
53
     }
48
     
54
     
49
-    @RequestMapping("/feignUser")
55
+    @RequestMapping(value = "/feignUser",method = RequestMethod.GET)
50
     @ResponseBody
56
     @ResponseBody
51
     public List<ScUser> getMicroUser(){
57
     public List<ScUser> getMicroUser(){
52
         return microTestController.getUser();
58
         return microTestController.getUser();

+ 6
- 0
SmartCommunity/SmartCommunityV1/zuul/pom.xml View File

36
 			<version>1.4.5.RELEASE</version>
36
 			<version>1.4.5.RELEASE</version>
37
 		</dependency>
37
 		</dependency>
38
 
38
 
39
+		<dependency>
40
+			<groupId>com.didispace</groupId>
41
+			<artifactId>swagger-butler-core</artifactId>
42
+			<version>1.0.0</version>
43
+		</dependency>
44
+
39
 		<dependency>
45
 		<dependency>
40
 			<groupId>org.springframework.cloud</groupId>
46
 			<groupId>org.springframework.cloud</groupId>
41
 			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
47
 			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

+ 2
- 0
SmartCommunity/SmartCommunityV1/zuul/src/main/java/com/example/demo/ZuulApplication.java View File

1
 package com.example.demo;
1
 package com.example.demo;
2
 
2
 
3
+import com.didispace.swagger.butler.EnableSwaggerButler;
3
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.cloud.client.SpringCloudApplication;
5
 import org.springframework.cloud.client.SpringCloudApplication;
5
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8
 @EnableZuulProxy
9
 @EnableZuulProxy
9
 @EnableDiscoveryClient
10
 @EnableDiscoveryClient
10
 @SpringCloudApplication
11
 @SpringCloudApplication
12
+@EnableSwaggerButler
11
 public class ZuulApplication {
13
 public class ZuulApplication {
12
 
14
 
13
 	public static void main(String[] args) {
15
 	public static void main(String[] args) {