1 Star 0 Fork 1

henrycn / spring-mvc-co

forked from float.lu / spring-mvc-co 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Spring MVC CO基于Spring MVC开发,对BigPipe进行支持。基本思想是模块化的页面包含多个模块而其中有些模块可能存在数据准备慢的情况,这个时候我们不应该让页面响应的速度等于最慢的那个模块的响应时间,而是能让最快准备好数据的那个模块先渲染然后吐给客户端,我们有可能放弃渲染石板的那个模块而不是放弃整个页面。

开始: 1.Spring MVC配置文件引入Spring-mvc-co的命名空间:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc/co"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc/co
        http://www.springframework.org/schema/mvc/spring-mvc-co.xsd">

       <mvc:annotation-driven>
       </mvc:annotation-driven>

</beans>

同时配置annotation-driven。 2.基于Freemarker的模板编写,该模板包括同步返回的DOM结构和引入的模块配置。

<#assign co=JspTaglibs["http://www.springframework.org/co"]>

<@co.config timeout=3000/>

${index!}


模块1:
<@co.module mapping="/co/module1"/>


模块2:
<@co.module mapping="/co/module2" />

说明: <@co.config timeout=3000/> 代表页面模块的超时时间为3s,超过该时间的模块将被放弃。 <@co.module mapping="/co/module1"/>配置引入的模块,和RequestMapping对应。

Controller例子:

@Controller
@RequestMapping("co")
public class CoController {

    @RequestMapping("index")
    public String index(Model model, String name){
        model.addAttribute("index", name);
        //返回数据和模板,同步返回
        return "co/index";
    }


    //ModelAndView并发执行和渲染
    @RequestMapping("module1")
    public String module1(Model model, String name){
        model.addAttribute("module1", name);
        try {
            //业务逻辑
            Thread.sleep(1000);
        } catch (Exception e) {

        }
        //模块模板
        return "co/module1";
    }

    //ModelAndView并发执行和渲染
    @RequestMapping("module2")
    public String module2(Model model, String name){
        model.addAttribute("module2",name);
        try {
            //业务逻辑
            Thread.sleep(800);
        } catch (Exception e) {

        }
        //模块模板
        return "co/module2";
    }
}

空文件

简介

基于spring mvc的big pipe实现 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/henrycn/spring-mvc-co.git
git@gitee.com:henrycn/spring-mvc-co.git
henrycn
spring-mvc-co
spring-mvc-co
master

搜索帮助