在postman中测试api时得到错误404

问题描述 投票:0回答:2

Model Class

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;
    }

}

Controller class

@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;
    }
}

qazxsw poi在开发Spring Boot Rest Api时遇到404错误。无法找到Error.Can有人帮我解决这个问题吗?

spring-boot spring-restcontroller spring-rest
2个回答
0
投票

上面的代码工作正常,你检查你的应用程序日志?

enter image description here


0
投票

检查您的enter image description here文件是否包含application.properties属性。如果是,请将其附加到域后的URL中。

server.servlet.context-path
© www.soinside.com 2019 - 2024. All rights reserved.