zoukankan      html  css  js  c++  java
  • Extjs的数据读取器store和后台返回类型简单解析

    工作中用到了Extjs,从后台获取数据的时候,用到了extjs自己的Ext.data.store方法,然后封装了ExtGridReturn方法,

    目的:前台用到Ext.data.store读取从后台传过来的数据,后台封装成ExtGridReturn类型

    前台如下:

    this.store = new Ext.data.Store({
                remoteSort:true,
                baseParams:{
                    start:0,
                    limit:this.pageSize
                },
                proxy:new Ext.data.HttpProxy({
                    method:'POST',
                    url:this.getAllUrl
                }),
                reader:new Ext.data.JsonReader({
                    totalProperty:'results',
                    root:'rows'
                },['rulesId','rulesTitle','rulesContent','rulesType','updateUser',{
                    name:'updateTime',
                    type:'date',
                    dateFormat:'time'
                },'rulesAuthor','isTop',{
                    name:'createTime',
                    type:'date',
                    dateFormat:'time'
                }])
            });

    当前的数据读取器是带有root和totalProperty的,所以,后台封装的类型如下:

    package cn.edu.hbcf.common.vo;
     
    import java.util.List;

    /**
     * Ext Grid返回对象
     *
     * @author LiPenghui
     *
     */
    public class ExtGridReturn {

        /**
         * 记录总条数
         */
        private int results;
        
        private int otherCount;
        /**
         * 所有数据
         */
        private List<?> rows;

        public ExtGridReturn() {

        }

        public ExtGridReturn(int results, List<?> rows) {
            this.results = results;
            this.rows = rows;
        }

        public int getResults() {
            return results;
        }

        public void setResults(int results) {
            this.results = results;
        }

        public List<?> getRows() {
            return rows;
        }

        public void setRows(List<?> rows) {
            this.rows = rows;
        }

        public int getOtherCount() {
            return otherCount;
        }

        public void setOtherCount(int otherCount) {
            this.otherCount = otherCount;
        }
        
        

    }
    Controller中的方法就可以这样写啦:如下:

    @RequestMapping(value="/selectBaseRules",method=RequestMethod.POST)
        @ResponseBody
        public Object selectBaseRules(ExtPager pager,int rulesType){
            Criteria criteria = new Criteria();
            if(pager.getStart() !=null &&pager.getLimit() !=null){
                criteria.setStart(pager.getStart());
                criteria.setLimit(pager.getLimit());
                criteria.setOracleStart(pager.getStart());
                criteria.setOracleEnd(pager.getStart() + pager.getLimit());
            }
            try {
                criteria.put("rulesType", rulesType);
                List<BaseRules> list = baseRulesService.selectBaseRules(criteria);
                int total= baseRulesService.getTotalCount();
                return new ExtGridReturn(total, list);
            } catch (Exception e) {
                e.printStackTrace();
                return new ExceptionReturn(e);
            }
        },

    mybatis中的xml配置文件如下:

    <select id="selectBaseRules" resultMap="BaseRulesMap" parameterType="Criteria">
        <include refid="common.Oracle_Pagination_Head" />
        select t.rules_id      rulesId,
                 t.rules_title   rulesTitle,
                  t.rules_content rulesContent,
               t.rules_type    rulesType,
               t.update_time   updateTime,
               t.rules_author  rulesAuthor,
               t.is_top        isTop,
               t.create_time   createTime,
               t.UPDATE_USER   updateUser,
               s.account       account,
               s.real_name     realName,
               s.user_id       userId
          from SMS_BASE_RULES t
          left join spauth.base_users s
            on s.user_id = t.update_user
            <where>
                t.rules_type=#{condition.rulesType,jdbcType=INTEGER}
            </where>
        <include refid="common.Oracle_Pagination_Tail" />
    </select>

    很简单的封装了Extjs读取的类型。

  • 相关阅读:
    The formatter threw an exception while trying to deserialize the message in WCF
    通过Web Deploy方式部署WCF
    The Managed Metadata Service or Connection is currently not available
    How to create Managed Metadata Column
    冒泡算法
    asp.net core 实战项目(一)——ef core的使用
    Vue学习笔记入门篇——安装及常用指令介绍
    Vue学习笔记入门篇——数据及DOM
    Vue学习笔记目录
    Chart.js在Laravel项目中的应用
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/4626978.html
Copyright © 2011-2022 走看看