我尝试创建一个返回字符串的@RequestMapping
方法(这是一个JSP文件的路径)
@RequestMapping(value="/home", method=RequestMethod.GET)
public String home(){
logger.info("home");
return "blog/home";
}
直到我在mvc:annotation-driven
文件中定义@ControllerAdvice
(我需要将其设置为能够使用dispatcher-servlet.xml
)时才能正常工作。这就是我的dispatcher-servlet.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="controllers.xml" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/*;charset=UTF-8" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
</beans>
将home()
方法的返回解释为HTTP正文。
我在我的日志中遇到了这个问题
Written [redirect:/blog/home] as "text/html" using [org.springframework.http.converter.StringHttpMessageConverter@61f77969]
我不知道我错过了这条道路&#34; blog / home&#34;不解释为视图参考