我正在使用 Spring Boot,并尝试显示 get 请求。我正在使用 2 个类:Greeting.java
和 GreetingController
:
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;
}
}
我的 Controller 是 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
我不明白为什么他找不到该页面。 如果有人可以帮助我:)
谢谢
最佳答案
映射 /greeting
存在,但发生错误,导致重定向到尚未配置的位置 /error
关于java - 导航器无法访问 RequestMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35924636/