Spring3 MVC 怎么配置同时使用多视图
2016-04-12 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询