RequestMapping canot可以被导航器

时间:2016-03-10 18:39:33

标签: java spring spring-boot

我正在使用Spring Boot,我尝试显示get请求。我使用了2个类:Greeting.javaGreetingController

    package greeting;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}

我的控制器是GreetingController.java:

public class GreetingController {

    private static final String template = "Hello ,%s!";
    private final AtomicLong counter  = new AtomicLong();

    @RequestMapping(value="/greeting",method = RequestMethod.GET)
    public Greeting greeting(@RequestParam(value = "name",defaultValue = "World")String name){
        return new Greeting(counter.incrementAndGet(),String.format(template,name));
    }
}

当我插入此网址(http://localhost:8080/greeting?name=gabriel)时,我在导航器上收到此错误:

  Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Mar 10 19:35:17 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available

我不明白为什么他没找到这个页面。 如果一个人可以帮助我:)。

谢谢

1 个答案:

答案 0 :(得分:1)

映射/greeting存在,但发生错误导致重定向到尚未配置的位置/error