Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

博主你好,发现一个错误,不知道是我的操作有问题,还是代码不正确 #25

Open
RockChuLee opened this issue Sep 21, 2020 · 0 comments

Comments

@RockChuLee
Copy link

本篇文章种有一部分讲述有关自定义响应消息的代码如下

.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(
new ResponseMessageBuilder()
              .code(500)
              .message("服务器发生异常")
              .responseModel(new ModelRef("Error"))
              .build(),
       new ResponseMessageBuilder()
              .code(403)
              .message("资源不可用")
              .build()
));

如果直接复制,会报以下错误。
Cannot resolve constructor 'ArrayList(springfox.documentation.service.ResponseMessage, springfox.documentation.service.ResponseMessage)'

应该是ArrayList的初始化问题

我做了如下修改

.useDefaultResponseMessages(false)
                .globalResponseMessage(RequestMethod.GET, new ArrayList() {{
                    add(new ResponseMessageBuilder()
                            .code(500)
                            .message("服务器发生异常")
                            .responseModel(new ModelRef("Error"))
                            .build());
                    add(new ResponseMessageBuilder()
                            .code(403)
                            .message("资源不可用")
                            .build());
                }})

问题解决。不知道是不是代码有问题,如果有问题希望可以起到一些帮助作用,如果是我理解有误,希望可以得到指正。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant