Skip to content

Commit 7853f0b

Browse files
committed
api
1 parent 5e69137 commit 7853f0b

File tree

88 files changed

+3069
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3069
-57
lines changed

api/pom.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>xiaomo</artifactId>
7+
<groupId>info.xiaomo</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>api</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>info.xiaomo</groupId>
17+
<artifactId>core</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.springfox</groupId>
22+
<artifactId>springfox-swagger-ui</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-data-jpa</artifactId>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-maven-plugin</artifactId>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
</project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package info.xiaomo.api;
2+
3+
import io.swagger.annotations.ApiOperation;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6+
import org.springframework.boot.autoconfigure.domain.EntityScan;
7+
import org.springframework.cache.annotation.EnableCaching;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.ComponentScan;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
12+
import org.springframework.scheduling.annotation.EnableAsync;
13+
import org.springframework.scheduling.annotation.EnableScheduling;
14+
import org.springframework.stereotype.Controller;
15+
import org.springframework.transaction.annotation.EnableTransactionManagement;
16+
import org.springframework.web.bind.annotation.RequestMapping;
17+
import org.springframework.web.bind.annotation.RequestMethod;
18+
import org.springframework.web.servlet.ModelAndView;
19+
import springfox.documentation.annotations.ApiIgnore;
20+
import springfox.documentation.builders.ApiInfoBuilder;
21+
import springfox.documentation.builders.PathSelectors;
22+
import springfox.documentation.builders.RequestHandlerSelectors;
23+
import springfox.documentation.service.ApiInfo;
24+
import springfox.documentation.spi.DocumentationType;
25+
import springfox.documentation.spring.web.plugins.Docket;
26+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
27+
28+
/**
29+
* 把今天最好的表现当作明天最新的起点..~
30+
* いま 最高の表現 として 明日最新の始発..~
31+
* Today the best performance as tomorrow newest starter!
32+
* Created by IntelliJ IDEA.
33+
*
34+
* @author: xiaomo
35+
* @github: https://github.com/qq83387856
36+
* @email: hupengbest@163.com
37+
* @QQ_NO: 83387856
38+
* @Date: 2016/4/1 15:38
39+
* @Description: 后台管理启动器
40+
* @Copyright(©) 2015 by xiaomo.
41+
**/
42+
@Configuration
43+
@EnableAutoConfiguration
44+
@ComponentScan("info.xiaomo")
45+
@EntityScan("info.xiaomo.*.model")
46+
@EnableTransactionManagement
47+
@EnableJpaRepositories("info.xiaomo.*.dao")
48+
@EnableScheduling
49+
@EnableAsync
50+
@EnableCaching
51+
@Controller
52+
@EnableSwagger2
53+
public class ApiMain {
54+
55+
public static void main(String[] args) throws Exception {
56+
SpringApplication.run(ApiMain.class, args);
57+
}
58+
59+
60+
/**
61+
* 接口
62+
*
63+
* @return 接口
64+
*/
65+
@RequestMapping(value = "/", method = RequestMethod.GET)
66+
@ApiIgnore()
67+
@ApiOperation(value = "重定向到api首页")
68+
public ModelAndView index() {
69+
return new ModelAndView("redirect:/swagger-ui.html");
70+
}
71+
72+
@Bean
73+
public Docket createRestApi() {
74+
return new Docket(DocumentationType.SWAGGER_2)
75+
.apiInfo(apiInfo())
76+
.select()
77+
.apis(RequestHandlerSelectors.basePackage("info.xiaomo.website"))
78+
.paths(PathSelectors.any())
79+
.build();
80+
}
81+
82+
private ApiInfo apiInfo() {
83+
return new ApiInfoBuilder()
84+
.title("Spring Boot中使用Swagger2构建RESTful APIs")
85+
.description("api根地址:http://api.xiaomo.info:8080/")
86+
.termsOfServiceUrl("http://blog.xiaomo.info/")
87+
.contact("小莫")
88+
.version("1.0")
89+
.build();
90+
}
91+
92+
}

0 commit comments

Comments
 (0)