All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.wboost.common.extend.SuffixInternalResourceViewResolver Maven / Gradle / Ivy

package top.wboost.common.extend;

/*
 * Copyright 2002-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.springframework.beans.BeanUtils;
import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * Convenient subclass of {@link UrlBasedViewResolver} that supports
 * {@link InternalResourceView} (i.e. Servlets and JSPs) and subclasses
 * such as {@link JstlView}.
 *
 * 

The view class for all views generated by this resolver can be specified * via {@link #setViewClass}. See {@link UrlBasedViewResolver}'s javadoc for details. * The default is {@link InternalResourceView}, or {@link JstlView} if the * JSTL API is present. * *

BTW, it's good practice to put JSP files that just serve as views under * WEB-INF, to hide them from direct access (e.g. via a manually entered URL). * Only controllers will be able to access them then. * *

Note: When chaining ViewResolvers, an InternalResourceViewResolver * always needs to be last, as it will attempt to resolve any view name, * no matter whether the underlying resource actually exists. * * @author Juergen Hoeller * @since 17.02.2003 * @see #setViewClass * @see #setPrefix * @see #setSuffix * @see #setRequestContextAttribute * @see InternalResourceView * @see JstlView */ /** * 修改获取视图文件后缀选择 * @author jwSun */ public class SuffixInternalResourceViewResolver extends InternalResourceViewResolver { protected AbstractUrlBasedView buildView(String viewName) throws Exception { AbstractUrlBasedView view = (AbstractUrlBasedView) BeanUtils.instantiateClass(getViewClass()); String url = null; //当为安全项目时,使用配置文件后缀(jsp) 当为其他项目时,使用html后缀 /*if (viewName.indexOf("security/") != -1) { url = getPrefix() + viewName + getSuffix(); } else { url = getPrefix() + viewName + ".html"; }*/ url = getPrefix() + viewName + getSuffix(); view.setUrl(url); String contentType = getContentType(); if (contentType != null) { view.setContentType(contentType); } view.setRequestContextAttribute(getRequestContextAttribute()); view.setAttributesMap(getAttributesMap()); Boolean exposePathVariables = getExposePathVariables(); if (exposePathVariables != null) { view.setExposePathVariables(exposePathVariables); } Boolean exposeContextBeansAsAttributes = getExposeContextBeansAsAttributes(); if (exposeContextBeansAsAttributes != null) { view.setExposeContextBeansAsAttributes(exposeContextBeansAsAttributes); } String[] exposedContextBeanNames = getExposedContextBeanNames(); if (exposedContextBeanNames != null) { view.setExposedContextBeanNames(exposedContextBeanNames); } InternalResourceView internalResourceView = (InternalResourceView) view; internalResourceView.setPreventDispatchLoop(true); return internalResourceView; } /** * Return the suffix that gets appended to view names when building a URL. */ /* protected String getSuffix() { //return super.super.suffix; return "2"; }*/ }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy