spring mvc InternalResourceViewResolver 没有获得前缀
spring mvc InternalResourceViewResolver doesnt get prefix
spring mvc InternalResourceViewResolver 没有从控制器获取前缀而是后缀。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="pizzaorder" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
控制器:
package pizzaorder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
@Controller
public class PizzaController {
@RequestMapping("/")
public ModelAndView getAlap(){
ModelAndView model1=new ModelAndView("index");
return model1;
}
}
如果我将后缀修改为index.jsp,效果很好。
如果左后缀 .jsp 它显示:
同样在调试中,我看到视图名称已正确传递:
好的,知道问题了!您在控制器中导入了错误的 ModelAndView class。应该是
import org.springframework.web.servlet.ModelAndView;
而不是
import org.springframework.web.portlet.ModelAndView;
更改此设置,您的应用程序将会非常棒!
spring mvc InternalResourceViewResolver 没有从控制器获取前缀而是后缀。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="pizzaorder" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
控制器:
package pizzaorder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;
@Controller
public class PizzaController {
@RequestMapping("/")
public ModelAndView getAlap(){
ModelAndView model1=new ModelAndView("index");
return model1;
}
}
如果我将后缀修改为index.jsp,效果很好。 如果左后缀 .jsp 它显示:
同样在调试中,我看到视图名称已正确传递:
好的,知道问题了!您在控制器中导入了错误的 ModelAndView class。应该是
import org.springframework.web.servlet.ModelAndView;
而不是
import org.springframework.web.portlet.ModelAndView;
更改此设置,您的应用程序将会非常棒!