001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.method.support; 018 019import org.springframework.core.MethodParameter; 020import org.springframework.web.context.request.NativeWebRequest; 021 022/** 023 * Strategy interface to handle the value returned from the invocation of a 024 * handler method . 025 * 026 * @author Arjen Poutsma 027 * @since 3.1 028 * @see HandlerMethodArgumentResolver 029 */ 030public interface HandlerMethodReturnValueHandler { 031 032 /** 033 * Whether the given {@linkplain MethodParameter method return type} is 034 * supported by this handler. 035 * @param returnType the method return type to check 036 * @return {@code true} if this handler supports the supplied return type; 037 * {@code false} otherwise 038 */ 039 boolean supportsReturnType(MethodParameter returnType); 040 041 /** 042 * Handle the given return value by adding attributes to the model and 043 * setting a view or setting the 044 * {@link ModelAndViewContainer#setRequestHandled} flag to {@code true} 045 * to indicate the response has been handled directly. 046 * @param returnValue the value returned from the handler method 047 * @param returnType the type of the return value. This type must have 048 * previously been passed to {@link #supportsReturnType} which must 049 * have returned {@code true}. 050 * @param mavContainer the ModelAndViewContainer for the current request 051 * @param webRequest the current request 052 * @throws Exception if the return value handling results in an error 053 */ 054 void handleReturnValue(Object returnValue, MethodParameter returnType, 055 ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception; 056 057}