Spring3 MVC 怎么配置同时使用多视图
展开全部
<context:component-scan base-package="com.spring" />
<bean id="freemarkerViewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1" />
<property name="prefix" value="/freemarker/" />
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html;charset=utf-8" />
<property name="viewClass">
<value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="2" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean>
<bean
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
@RequestMapping(value="/student")
protected ModelAndView freemaker() {
Student stu1=new Student();
stu1.setName("gaoxiang1");
stu1.setSex("male1");
Student stu2=new Student();
stu2.setName("gaoxiang2");
stu2.setSex("male2");
List a=new ArrayList();
a.add(stu1);
a.add(stu2);
return new ModelAndView("user/student","studentList",a);
}
使用视图链 首先会去找 user/student.ftl 如果找不到就会去找 user/student.jsp
<bean id="freemarkerViewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1" />
<property name="prefix" value="/freemarker/" />
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html;charset=utf-8" />
<property name="viewClass">
<value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="2" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean>
<bean
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
@RequestMapping(value="/student")
protected ModelAndView freemaker() {
Student stu1=new Student();
stu1.setName("gaoxiang1");
stu1.setSex("male1");
Student stu2=new Student();
stu2.setName("gaoxiang2");
stu2.setSex("male2");
List a=new ArrayList();
a.add(stu1);
a.add(stu2);
return new ModelAndView("user/student","studentList",a);
}
使用视图链 首先会去找 user/student.ftl 如果找不到就会去找 user/student.jsp
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询