spring3 多视图集成

阅读更多
使用spring3.2.9 集成多视图,可以使用jsp页面,ftl页面,vm页面。

源代码在附件中
主要配置:

class="org.springframework.beans.factory.config.PropertiesFactoryBean">




class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">














class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">



value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />



















class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">





text/html;charset=UTF-8


















    class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">










class="org.springframework.web.servlet.view.InternalResourceViewResolver">


value="org.springframework.web.servlet.view.JstlView" />



 









java类代码:

访问jsp 页面:
@Controller
@RequestMapping("/jsp")
public class JspController {

@RequestMapping("/list")
public ModelAndView list(){
ModelAndView modelAndView = new ModelAndView("list.jsp");
modelAndView.addObject("name", "jsp........");

return modelAndView;

}
}

访问ftl页面:

@Controller
@RequestMapping("/ftl")
public class FtlController {

@RequestMapping("/hello")
public ModelAndView hello(){
ModelAndView model = new ModelAndView("hello.ftl");//文件后缀必须填写
model.addObject("name", "boce...");
return model;
}
}


访问 vm页面:


@Controller
@RequestMapping(value = "/demo")
public class DemoVelocity {
// Logger logger = LoggerFactory.getLogger(VelocityDemo.class);
@RequestMapping(value = "/welcome")
public String index(Model model) throws Exception {
model.addAttribute("name", "highkgao");

model.addAttribute("age", 20);
model.addAttribute("date", Calendar.getInstance().getTime());

//model.a
System.out.println(model.toString());

return "welcome.vm"; //文件后缀必须填写
}



@RequestMapping(value = "/test.do")
public String test(Model model) throws Exception {
model.addAttribute("name", "highkgao");


System.out.println(model.toString());
return "index";
}


@RequestMapping(value="/autoBind", method={RequestMethod.GET})
  public String autoBindLogin(Model model){
      model.addAttribute("accountmodel", new AccountModel());
      return "login";
  }


@RequestMapping(value="/autoBind2", method={RequestMethod.POST})
    public String autoBindResult(Model model,AccountModel am){
        model.addAttribute("accountmodel",am );
        return "autoBindResult";
    }

}



访问后页面显示:

jsp页面:

spring3 多视图集成_第1张图片


vm页面


spring3 多视图集成_第2张图片

ftl页面


spring3 多视图集成_第3张图片




  • spring3 多视图集成_第4张图片
  • 大小: 29.5 KB
  • spring3 多视图集成_第5张图片
  • 大小: 36 KB
  • spring3 多视图集成_第6张图片
  • 大小: 30.2 KB
  • spring3 多视图集成_第7张图片
  • 大小: 24 KB
  • boce-all-velocityweb.zip (43.2 KB)
  • 下载次数: 0
  • 查看图片附件

你可能感兴趣的:(spring,freemark,velocity)