【发布时间】:2015-11-10 09:57:54
【问题描述】:
我是 Spring Boot 的新手。在以下简单代码中,当我使用@RequestMapping 时,http://localhost:8080/person 会导致以下错误:
错误:
There was an unexpected error (type=Not Found, status=404).
代码:
@Configuration
@EnableAutoConfiguration
@ComponentScan
@Controller
public class SpringBootAlphaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAlphaApplication.class, args);
}
@RequestMapping("/person")
public String addPerson(Model model){
Person person = new Person();
person.setName("SomeName");
person.setAge(28);
model.addAttribute("person", person);
return "personview";
}
@RequestMapping("/")
public String testPath(){
return "Test URL";
}
}
【问题讨论】:
-
您要返回什么?你要返回html还是json?
-
@ksokol addPerson 将返回 html,但 testPath 方法应该返回一个简单的字符串,但找不到资源。需要注意的一点是,如果我将 ResponseBody 与 RequestMapping 一起使用,则会返回它
-
您想使用什么模板引擎? JSP、Freemarker、Velocity、Thymleaf?
标签: spring web-applications spring-boot http-status-code-404