@RestController=@Controller+@ResponseBody
1. Use RestController, return to the front of the content is Return the contents can not be returned jsp / html page, etc.,
In this case, application-spring.xml profile, does not require configuration view resolver
1 <!-- 3.配置jsp 显示ViewResolver --> 2 <bean id="viewResolver" 3 class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 4 <property name="viewClass" 5 value="org.springframework.web.servlet.view.JstlView" /> 6 <property name="prefix" value="/WEB-INF/jsp/" /> 7 <property name="suffix" value=".jsp" /> 8 </bean>
NOTE: view resolver will return control layer according to parse the string, if it was return "hello", after the parser will automatically add the prefix and suffix into /WEB-INF/view/hello.jsp.
2. To return to the specified page, @Controller may be used, with the above view resolver, if necessary to return JSON, XML or custom mediaType content to a page, you need to add annotations on @ResponseBody corresponding method.