1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.web.servlet.mvc.method.annotation;
18
19 import org.springframework.core.MethodParameter;
20 import org.springframework.web.context.request.NativeWebRequest;
21 import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
22 import org.springframework.web.method.support.ModelAndViewContainer;
23 import org.springframework.web.servlet.RequestToViewNameTranslator;
24 import org.springframework.web.servlet.SmartView;
25 import org.springframework.web.servlet.View;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
42
43 @Override
44 public boolean supportsReturnType(MethodParameter returnType) {
45 return View.class.isAssignableFrom(returnType.getParameterType());
46 }
47
48 @Override
49 public void handleReturnValue(Object returnValue, MethodParameter returnType,
50 ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
51
52 if (returnValue == null) {
53 return;
54 }
55 else if (returnValue instanceof View){
56 View view = (View) returnValue;
57 mavContainer.setView(view);
58 if (view instanceof SmartView) {
59 if (((SmartView) view).isRedirectView()) {
60 mavContainer.setRedirectModelScenario(true);
61 }
62 }
63 }
64 else {
65
66 throw new UnsupportedOperationException("Unexpected return type: " +
67 returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
68 }
69 }
70
71 }