springboot 集成swagger ui

springboot 集成swagger ui

springboot 配置swagger ui

1.添加依赖

 <!--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. 启动swagger ui注解

package com.wxy97.blog;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
public class BlogApplication {

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

}

3. controller中添加注解

package com.wxy97.blog.web.admin;

import com.wxy97.blog.po.User;
import com.wxy97.blog.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: wxySmile
 * @Date 19-11-10 下午12:19
 */
@Controller
@RequestMapping("/admin")
@Api("管理员")
public class LoginController {

    @Autowired
    private UserService userService;

    @GetMapping
    @ApiOperation("后台 登录页面")
    public String loginPage(){
        System.out.println("admin登录");
        return "admin/login";
    }

    @PostMapping("/login")
    @ApiOperation("登录校验功能")
    @ResponseBody()
    public String login(@RequestParam String username, @RequestParam String password, HttpSession session){
        System.out.println(username+"密码"+password);
        User user = userService.checkUser(username, password);
        if (user!=null){
            //登陆成功
            user.setPassword(null);
            session.setAttribute("user",user);
            return "admin/index";
        }else {
            return "redirect:/admin";
        }
    }
}

4.启动程序 localhost:8080/swagger-ui.html (默认)

image

5.官网http://swagger.io/

最后修改:2019 年 11 月 10 日 01 : 41 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论