我是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? –