24 springcloud 集成swagger2

1,pom.xml


  <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.7.0.RELEASE</version>
        </dependency>

2,yml配置里添加配置:


swagger:
  base-package:  com.itmayidu.api.service

3,启动类添加注解: @EnableSwagger2//表示生成swagger2文档


package com.itmayidu.api.service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 *@author tom
 *Date  2020/4/21 0021 23:28
 *
 */
@EnableSwagger2//表示生成swagger2文档
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class AppMember {
    public static void main(String[] args) {
        SpringApplication.run(AppMember.class,args);
    }
}

4,类:

package com.itmayidu.api.service.impl;



import com.itmayidu.api.entity.UserEntity;
import com.itmayidu.api.service.IMemberService;
import com.taotao.BaseApiService;
import com.taotao.ResponseBase;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *@author tom
 *Date  2020/4/21 0021 20:23
 *
 */
@Api("会员服务")
@RestController
public class MemberServiceImpl extends BaseApiService implements IMemberService {
    @Value("${server.port}")
    private String serverport;
    @ApiOperation("添加用户的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四")}
    )
    @GetMapping("index")
    public  String index(String name){
        return  name;
    }
    @Override
    @RequestMapping("/getMember")
    public UserEntity getMember(@RequestParam(value = "name") String name) {
        UserEntity userEntity = new UserEntity();
        userEntity.setName(name);
        userEntity.setAge(21);
        return userEntity;
    }

    @Override
    @RequestMapping("/getUserInfo")
    public ResponseBase getUserInfo() throws InterruptedException {
       //请求延迟
        System.out.println("订单服务调用会员服务");
        Thread.sleep(1500);
        return setResultSuccess("订单服务调用会员服务接口成功......"+ "端口号:"+serverport);
    }
}


image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。