Giter Site home page Giter Site logo

ganchaoyang / spring-tutorial Goto Github PK

View Code? Open in Web Editor NEW
183.0 9.0 142.0 145 KB

本项目是我个人在编写Spring Boot系列博客的源代码,会持续不断更新。如果项目中的代码有错误,望大家一起勘正~。

Home Page: https://itweknow.cn

Java 98.76% TSQL 1.24%
springboot java

spring-tutorial's Issues

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

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

.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());
                }})

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.