springboot integrated swagger automatically generated API documentation

Swagger is a standardized and complete framework for generating, description, and visualization calls for RESTful Web services. In simple terms, Swagger is a powerful interface management tools, and provides a variety of programming languages ​​before and after the end of the separation solutions.

  • Swagger can be integrated into the code at development through notes, writing notes, automatically generated API documentation;
  • Separating the front and rear ends to facilitate the development of

What swagger that?

API Developmentfor Everyone

springboot integrated swagger

1, add pom-dependent

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

2, add swagger configuration

@EnableSwagger2
@RestController
@SpringBootApplication
public class FamilyServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(FamilyServerApplication.class, args);
    }

    @RequestMapping("/")
    public String hello(){
        return "hello billy!";
    }
}

3, add annotations on need API exposed API

E.g:

@Api("MemberManageController")
@RestController
@RequestMapping("member")
public class MemberManageController extends BaseController {

    @Autowired
    private MembersManageService manageService;

    /**
     *  获取成员
     * @return
     */
    @ApiOperation(value = "查询家庭成员", notes = "查询家庭成员")
    @ApiImplicitParams(@ApiImplicitParam(name = "name", value = "姓名", paramType = "query", dataType = "String"))
    @RequestMapping("getMembers")
    public Object getMembers(String name){

        logger.debug("开始。。。");
        System.out.println(name);
        Page<FamilyMembers> page = new Page<>();
        IPage<FamilyMembers> membersByPage = manageService.getMembersByPage(page);
        Messager result = messager.successObjectResponse(membersByPage);
        return result;
    }
}

4, start the project, visit swagger-ui address 

Demonstrations address:  HTTP: // localhost: 9090 / Swagger-ui.html

The results are as follows:

5, debugging interfaces

Return result:

 

 

Note: project development, if the front and rear ends of the separation, the use of swagger particularly convenient.

Guess you like

Origin www.cnblogs.com/BillyYoung/p/11024742.html