Spring Bootはswaggerと組み合わせて使用

1769 ワード

pomでの構成
        
        
            io.springfox
            springfox-swagger2
            2.5.0
        
        
            io.springfox
            springfox-swagger-ui
            2.5.0
        

クラスに注釈を付ける
@EnableSwagger2

Controllerでの構成(ここでnotesはmarkdownをサポート)
/**
 * Created by johnzh on
 * 2017/4/21. 22:08
 */
@Api(description = "    ")
@RestController
@RequestMapping(value = "/merchant")
public class MerchantController extends BaseController{

    private final MerchantService merchantService;

    @Autowired
    public MerchantController(MerchantService merchantService) {
        this.merchantService = merchantService;
    }

    @ApiOperation(value = "      ", httpMethod = "GET", notes = ApiNote.BACKLOG)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "  ", paramType = "query", name = "page", dataType = "int", required = true),
            @ApiImplicitParam(value = "  ", paramType = "query", name = "size", dataType = "int", required = true)
    })
    @GetMapping(value = "/backLog", produces = "application/json;charset=UTF-8")
    public String getBackLog(@Param("page") Integer page, @Param("size") Integer size, HttpSession session){
        Integer userId = getUserId(session);
        List orderDOList = merchantService.getBackLog(userId, page, size);
        return responseList(orderDOList);
    }
}