001/* 002 * Copyright 2002-2017 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.lang.Nullable; 021import org.springframework.web.context.request.NativeWebRequest; 022 023/** 024 * Strategy interface to handle the value returned from the invocation of a 025 * handler method . 026 * 027 * @author Arjen Poutsma 028 * @since 3.1 029 * @see HandlerMethodArgumentResolver 030 */ 031public interface HandlerMethodReturnValueHandler { 032 033 /** 034 * Whether the given {@linkplain MethodParameter method return type} is 035 * supported by this handler. 036 * @param returnType the method return type to check 037 * @return {@code true} if this handler supports the supplied return type; 038 * {@code false} otherwise 039 */ 040 boolean supportsReturnType(MethodParameter returnType); 041 042 /** 043 * Handle the given return value by adding attributes to the model and 044 * setting a view or setting the 045 * {@link ModelAndViewContainer#setRequestHandled} flag to {@code true} 046 * to indicate the response has been handled directly. 047 * @param returnValue the value returned from the handler method 048 * @param returnType the type of the return value. This type must have 049 * previously been passed to {@link #supportsReturnType} which must 050 * have returned {@code true}. 051 * @param mavContainer the ModelAndViewContainer for the current request 052 * @param webRequest the current request 053 * @throws Exception if the return value handling results in an error 054 */ 055 void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, 056 ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception; 057 058}