spring boot 使用Swagger2

pom.xml

 <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>
/**
 * Created by jiyang on 17:09 2017/12/21
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket swaggerSpringfoxDocket() {
        Docket swaggerSpringMvcPlugin = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("group-name")
                .genericModelSubstitutes(ResponseEntity.class)
                .select()
                .paths(regex(".*")) // and by paths
                .build();
        return swaggerSpringMvcPlugin;
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo("api-title",
                "api描述",
                "V1",
                "",
                "xxx.com",
                "MIT License",
                "/LICENSE");
        return apiInfo;
    }
}
/**
 * Created by jiyang on 16:10 2017/12/15
 */
@Controller
@RequestMapping("/tester")
@Api(value = "测试页面", description = "测试页面相关接口")
public class TestController {

    @Autowired
    private CacheRequestService cacheRequestService;

//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;

    @Value("${message.data.name:2}")
    private String name;

    @Value("${message.data.password:ps}")
    private String password;

    @ApiOperation(value="创建用户", notes="根据User对象创建用户")
    @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    @RequestMapping(value = "/vip/upgrade", method = RequestMethod.GET)
    @ResponseBody
    public Object vipUpgrade() {
        cacheRequestService.listUsers();
        return this.password;
    }

    @ApiOperation(notes = "直接显示页面", value = "同步请求获券包列表页面")
    @RequestMapping(value = "/v2", method = RequestMethod.GET)
    @ResponseBody
    public Object getV(@RequestParam(value = "access_token", required = false) String access_token, Map<String, Object> map) {
        return "hello v2";
    }

    @ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    })
    @RequestMapping(value = "/v3", method = RequestMethod.GET)
    public Object getV3(@RequestParam(value = "access_token", required = false) String access_token, Map<String, Object> map) {
        return "hello v3";
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值