c 调用rest 返回html,Spring rest controller不返回html

我正在使用 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";

}

我认为百里香或类似的软件可以让你放弃文件扩展名,但不确定 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值