【问题标题】:While testing api in postman getting error 404在邮递员中测试 api 时出现错误 404
【发布时间】:2019-08-05 18:53:39
【问题描述】:

模型类

public class SimpleResponse {

    private String message;
    private long id;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

}

控制器类

@RestController
public class WebController {

    // @RequestParam indicates that the endpoint /sample will have one Query
    // parameter called name.
    @RequestMapping("/sample")
    public SimpleResponse sample(@RequestParam(value = "name", defaultValue = "Kabir") String name) {
        SimpleResponse sm = new SimpleResponse();
        sm.setId(1);
        sm.setMessage("This message is for Kabir"+name);
        return sm;
    }
}

在开发 Spring Boot Rest Api 时出现 404 错误。找不到错误。谁能帮我解决这个问题?

【问题讨论】:

标签: spring-boot spring-restcontroller spring-rest


【解决方案1】:

以上代码运行良好,您检查过您的应用程序日志吗?

【讨论】:

    【解决方案2】:

    检查您的application.properties 文件是否包含server.servlet.context-path 的属性。如果是,则将其附加到您的 URL 之后的域。

    http://localhost:8888/<append_here>/sample?name=Kabir
    

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 2020-02-05
      • 2019-07-14
      • 2021-05-13
      • 2022-09-23
      • 2021-01-12
      • 2019-05-14
      • 2021-05-12
      相关资源
      最近更新 更多