【发布时间】:2016-11-23 14:34:03
【问题描述】:
我使用RestController 通过AngularJS 获取数据,但我仍然需要常规 控制器来加载index.html:
@Controller
public final class LayoutController {
@RequestMapping(value = "/")
public String getIndexPage() {
return "/resources/index";
}
}
所有其他控制器都是RestControllers。如果索引文件有jsp 扩展名,我不需要LayoutController,但是当它是html 时需要它。
这是我的dispatcher 配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="1"></property>
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.html</value>
</property>
</bean>
</beans>
这是applicationContext的一部分:
<mvc:annotation-driven/>
<tx:annotation-driven />
<mvc:resources mapping="/resources/**" location="WEB-INF/resources/" />
当我想使用index.html 而不是index.jsp 时,有没有办法摆脱LayoutController?提前感谢您的帮助。
基于公认答案的解决方案:
<mvc:view-controller path="/" view-name="/resources/index.html"/>
完全没有LayoutController 和InternalResourceViewResolver。
【问题讨论】:
标签: java angularjs spring spring-mvc spring-4