2016-05-15 138 views
1

这是一个springboot的控制器,我想写一个函数来重定向到一个html页面,但它总是以404响应,这里是代码和属性。 'spring引导重定向到html页面

@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"; 
} 
} 

' application.properties '

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

spring.view.suffix=.html 

'

程序可以进入功能和输出就可以了。 index.html位于此路径中:/WEB-INF/views/index.html。还有其他配置吗? 非常感谢

+0

你在尝试什么网址?根据你的配置,当你点击'http:// ... contextPath/Weixin/homepage'时,你应该看到'index.html'。 –

+0

@SanjayRawat的网址是localhost:8080/Weixin/homepage,但它回应404 – nasuf

+0

atComponent是多余的。你只需要atController。不确定是否会导致问题。 – code

回答

1

你有不正确的配置,试试这个:

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

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

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