Spring3 MVC 怎么配置同时使用多视图
1个回答
2016-07-15 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
<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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询