我正在使用 spring 启动1.5.2,我的 spring 控制器看起来像这样
@RestController
@RequestMapping("/")
public class HomeController {
@RequestMapping(method=RequestMethod.GET)
public String index() {
return "index";
}
}
当我去http://localhost:8090/assessment/它到达我的控制器但没有返回我的index.html,它位于src / main / resources或src / main / resources / static下的maven项目中 . 如果我转到此URL http://localhost:8090/assessment/index.html,它将返回我的index.html . 我看了这个教程https://spring.io/guides/gs/serving-web-content/,他们使用百里香 . 我是否必须使用百日咳或类似的东西给我的 Spring 季休息控制器回复我的观点?
我的应用程序类看起来像这样
@SpringBootApplication
@ComponentScan(basePackages={"com.pkg.*"})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
当我将thymeleaf依赖项添加到我的类路径时,我收到此错误(500响应代码)
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
我想我确实需要百里香?我现在要尝试正确配置它 .
更改我的控制器方法后返回index.html就可以了
@RequestMapping(method=RequestMethod.GET)
public String index() {
return "index.html";
}
我认为百里香或类似的软件可以让你放弃文件扩展名,但不确定 .