How to use multiple places in Spring viewresolver?

2019-09-04 14:50发布

this is how I define the loaction of my jsp files:

<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

But I have too many JSP files in one folder at the moment...I changed my directiory structure to this:

/WEB-INF/jsp/city/*.jsp
/WEB-INF/jsp/weather/*.jsp

How must I change my viewresolver so that both places are found?

Ask for more info if needed.

2条回答
相关推荐>>
2楼-- · 2019-09-04 15:28

Don't change it at all, just return qualified view names, e.g.

"city/tokyo" or "weather/partlyCloudy"

查看更多
乱世女痞
3楼-- · 2019-09-04 15:29

I'm sure the Sean Patrick Floyd answer is a better way to do this, but if you are not willing to use that technique, define two view resolvers, one with the prefix "/WEB-INF/jsp/city" and the other with the prefix "/WEB-INF/jsp/weather".

查看更多
登录 后发表回答