我是Spring Boot的新手。在下面簡單的代碼,當我使用@RequestMapping,http://localhost:8080/person導致以下錯誤:RequestMapping 404結果 - Spring Boot
錯誤:
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方法應該返回一個簡單的String,但是找不到資源。有一點需要注意的是,如果我將ResponseBody與RequestMapping一起使用,它會返回 – user3163473
您想使用哪種模板引擎? JSP,Freemarker,Velocity,Thymleaf? –