redirect - Spring Boot重定向到html页面

标签 redirect spring-boot

这是springboot的一个 Controller ,我想写一个重定向到html页面的函数,但它总是响应404,这是代码和属性。 '

@Component

@Controller

@RequestMapping("/Weixin")

public class KindlePocketController {

private static final long serialVersionUID = 1L;

@Autowired
private TextBookInfoSearchService searchService;

@RequestMapping("/homepage")
public String toIndex() {
    System.out.println("redirecting to homepage...");
    return "index";
}
}

' 应用程序属性 '

spring.view.prefix=/WEB-INF/views/

spring.view.suffix=.html

'

程序可以进入函数并且输出正常。而index.html在这个路径中:/WEB-INF/views/index.html。还有其他配置吗? 非常感谢

最佳答案

您的配置不正确,请尝试以下操作:

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.html

它是spring.mvc.view.*,而不是spring.view.*

PS:使用STS或InteliJ提供的Intelisense。

关于redirect - Spring Boot重定向到html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37234033/

相关文章:

java - 在 JPA 中插入之前忽略选择

REST Controller 中的 Spring Boot 绑定(bind)和验证错误处理

.htaccess - 301 将所有内容重定向到新根?

即使在删除空格后,PHP header 在 MAMP 中也不起作用

java - Spring Boot RESTFUL Controller 的单元测试

java - 在插件中和通过 Tomcat 覆盖 Spring Boot application.properties 属性?

java - spring boot 启动应用程序失败,未指定数据库url

apache - 向 htaccess 文件添加通配符 IP 范围?

基于子域的Apache重写

redirect - 如何在 ColdFusion 中重定向并控制状态代码(即 301 而不是 302)