springboot整合swagger

springboot整合swagger

新建配置类SwaggerConfig
(不用配置.yaml文件啥的)

package com.twoGroup.boot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.twoGroup.boot.controller")) //扫描包所在位置
                .paths(PathSelectors.any())
                .build();
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("二手交易平台")  //整个项目的名称
                .description("阿巴阿巴交易平台") //项目描述
                .termsOfServiceUrl("https://blog.csdn.net/YSecret_Y?spm=1000.2115.3001.5113")
                .version("1.0")
                .build();
    }
}

加入swagger注解

package com.twoGroup.boot.controller;


import com.twoGroup.boot.pojo.Address;
import com.twoGroup.boot.service.imp.AddressServiceImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/Address")
public class AddressController {
    @Resource
    private AddressServiceImpl addressService;


    //添加新的收件人
    @ApiOperation(value = "添加新的收件人(<=5)", notes = "传入userId(用户id)")
    @PostMapping("/addAddressee")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId",value = "用户id"),
                    @ApiImplicitParam(name="addressee",value = "收件人名字(长度1-6 跟nickname,可以不是真实姓名)"),
                    @ApiImplicitParam(name = "addresseeTelephone",value = "收件人手机号(11为且第一个值为1)"),
                    @ApiImplicitParam(name = "address",value = "收件人地址")
            }
    )
    @ResponseBody
    public List<Address> addAddressee(Integer userId, String addressee, String addresseeTelephone, String address){
        List<Address> addresses = addressService.queryAllAddressee(userId);
        if(addressService.queryAddress(userId)<=5){
            addressService.addAddressee(userId, addressee, addresseeTelephone, address);
            return addressService.queryAllAddressee(userId);
        }
        return addresses;
    }

完成图
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值