如何在spring加载HTML视图?
问题内容:
我当前用于解析html视图的代码是这样的
<mvc:resources mapping="/static/**" location="/WEB-INF/static/html/" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="" />
<property name="suffix" value=".html" />
</bean>
但是我需要返回诸如
return "/static/html/index";
我怎么能这样呢?
return "index";
问题答案:
将前缀更改为 /static/html/
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/static/html/" />
<property name="suffix" value=".html" />
</bean>
因此,当您返回时,"index"
它将变为/static/html/index.html
。