swagger可以显示二维码图片的正常配置

@Api(tags = "二维码下载接口")
@Controller
public class QrCodeController {
    @Autowired
    private SysApkService sysApkService;
    /**
     * make the QRCode by url
     * @param response
     * @param id
     * @throws IOException
     */
    @ApiOperation(value = "生成二维码",notes = "生成二维码")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query",name = "id",value = "ID",required = true)
    })
    @GetMapping("/qrcode/createCommonQRCode")
    @CrossOrigin(origins = "*", allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET, RequestMethod.DELETE, RequestMethod.HEAD, RequestMethod.OPTIONS, RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH})
    @ResponseBody
    public void createCommonQRCode(HttpServletResponse response,
                              Long id) throws IOException {
        System.out.println("id:"+id);

        ServletOutputStream stream = null;
        try{
            SysApk sysApk = sysApkService.findById(id);
            //返回图片内容
            response.setContentType("image/jpeg");
            stream = response.getOutputStream();
            //String imgUrl = "./";
            //produce the QRCode
            QRCodeUtil.encode(sysApk.getApkUrl(),
                    "/usr/local/hc_logo.png",sysApk.getApkName(),stream,true);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(stream != null){
                stream.flush();
                stream.close();
            }
        }
    }
}
发布了96 篇原创文章 · 获赞 45 · 访问量 7302

猜你喜欢

转载自blog.csdn.net/weixin_43404791/article/details/104995777