IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    LigerUI表格LigerGrid动态结合Struts2获取数据

    ShelWee发表于 2013-12-27 12:33:31
    love 0

    JSON是一种轻量级的数据交换格式,大部分地方都可方便地使用。
    Struts2通过利用JSON插件,也可以轻松的提供JSON数据供前台访问。

    1.准备工作

    本文在搭建好的struts2框架与LigerUI 插件的基础上实现的,框架的搭建不在本文的讨论范围。
    以下Action用到的JSON类是alibaba的开源类库Fastjson。

    相关工具包:struts2 v2.1.8、LigerUI v1.2.2、fastjson-1.1.9

    2.创建Action

    public class DeptAction extends ActionSupport{
        private JSONObject rows;
        public String getDepts() throws Exception{
                DeptService deptService = new DeptService();
                List depts= deptService.getDepts();
                HashMap maps = new HashMap();
                List> list = new ArrayList>();
                 for (Dept dept :depts) {
                      HashMap hashMap = new HashMap();
                      hashMap.put("id",dept.getId());
                      hashMap.put("name",dept.getName());
                      list.add(hashMap);
                }
                maps.put("Rows", list);
                rows = JSONObject.parseObject(JSON.toJSONString(maps));
                return SUCCESS;
        }
    
        public JSONObject getRows() {
                 return rows ;
        }
    
        public void setRows(JSONObject rows) {
                 this.rows = rows;
        }
    }

    3.Action配置

    
        
            rows
        
    

    4.LigerGrid请求数据

    Action创建并配置好之后,就可以在相应的页面发起请求。请求示例:

    5.效果

    ligerGrid



沪ICP备19023445号-2号
友情链接