How to use multiple places in Spring viewresolver?

2019-09-04 14:42发布

问题:

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.

回答1:

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

"city/tokyo" or "weather/partlyCloudy"



回答2:

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".