ExtJs+SSH框架数据显示在前台的问题

我要进行一个分组统计的功能,查询一张数据库表,然后把它显示在前台。但数据库表里面是没有相应的这个字段的。我先贴代码吧。
xml代码:

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<hibernate-mapping>
    < class name= "cn.gzjp.base.cms.entity.ActivitySum" table= "tb_sms_join" >
        <id name= "id" type= "java.lang.Integer" >
            <column name= "id" />
            <generator class = "native" >
                <param name= "sequence" >activity_seq</param>
            </generator>
        </id>
        <property name= "mdn" type= "java.lang.String" >
            <column name= "mdn" length= "30" />
        </property>
        <property name= "activityId" type= "java.lang.Integer" >
            <column name= "ACTIVITY_ID" length= "30" />
        </property>       
        <property name= "joinTime" type= "timestamp" >
            <column name= "JOIN_TIME" length= "20" />
        </property>     
    </ class >
</hibernate-mapping>


持久化的代码:

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class ActivitySum {
   
    private Integer id;
   
    private Integer activityId;
   
    private String mdn;
   
    private Date joinTime;
 
    public ActivitySum() {
        super ();
    }
 
    public ActivitySum(Integer id, Integer activityId, String mdn, Date joinTime) {
        super ();
        this .id = id;
        this .activityId = activityId;
        this .mdn = mdn;
        this .joinTime = joinTime;
    }
...


我就是想进行对activityId分组统计,显示在前台是activityId这个字段和统计的数量。
我查数据库这层代码:

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public PageList<ActivitySum> findByPage(ActivitySum entity, PageInfo pageInfo) {
    PageList<ActivitySum> pList = new PageList<ActivitySum>();
    List<ActivitySum> list= null ;
    pList.setTotalCount( 20 );
    if (entity != null ) {   
        if (entity.getMdn()!= null ){
        }
       
        if (entity.getJoinTime()!= null ){
        }
        if (entity.getMdn()== null &&entity.getJoinTime()== null ){               
            Session session = getBindDao().getSessionFactory().getCurrentSession();
            String sql = "select activity_id activityId ,count(*) mdn from tb_sms_join group by activity_id" ;
            SQLQuery sqlQuery = session.createSQLQuery(sql);               
            list = sqlQuery.list();                   
        }
        pList.setList(list);
       
        return pList;
    } else {
       
         return pList;
    }
}


这个是开始加载页面时会调用到这个方法,就是在Action里面调用的。
action的代码如下:

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cn.gzjp.base.cms.web.action.system;
 
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
 
import cn.gzjp.base.cms.entity.ActivitySum;
import cn.gzjp.base.cms.entity.SmsJoin;
import cn.gzjp.base.cms.service.ActivitySumService;
import cn.gzjp.base.cms.service.CommonService;
import cn.gzjp.base.cms.web.action.CmsJsonAction;
 
import com.opensymphony.xwork2.Action;
 
@Namespace ( "/system" )
@Results ({   
//    @Result(name=Action.SUCCESS, type = "json", params={
//            "excludeProperties","pageList\\.list\\[\\d+\\]\\.(cmsRights|cmsRoles)(1)*,pageList\\.list\\[\\d+\\]\\.cmsRight\\.(cmsRight|cmsRights|cmsRoles)(1)*",
//            "includeProperties","success,msg,pageList.*"}),//返回pageList到第三层属性
 
    //返回主页面
    @Result (name=CmsJsonAction.INDEX, type = "dispatcher" , location= "/system/activity-sum/index.jsp" )
 
})
public class ActivitySumAction extends CmsJsonAction<ActivitySum,Integer> {
   
    @Autowired
    private ActivitySumService activitySumService;
 
    @Override
    public CommonService getCommonService() {
        return activitySumService;
    }
 
    @Override
    public Integer[] getIds() {
        return this .ids;    }
 
    @Override
    public ActivitySum getModel() {
        if ( this .model== null ){
        this .model = new ActivitySum();
    }
    return this .model;
    }
 
    @Override
    protected void prepareModel() throws Exception {       
        if ( this .model!= null && this .model.getId()> 0 ){                       
            this .model = this .activitySumService.getByPk( this .model.getId());           
        }
    }
   
    public void prepareSave() throws Exception{
    prepareModel();
    if ( this .model!= null && this .model.getId()> 0 ){                       
        this .model = this .activitySumService.getByPk( this .model.getId());           
    }
}
 
    @Override
    public void setIds(Integer[] ids) {
        this .ids = ids;
       
    }
 
    @Override
    public void setModel(ActivitySum model) {
        this .model = model;
       
    }
 
    @Override
    public String list() throws Exception {
       
        try {
            log.debug( "list modol=" + getModel());
            this .pageList = this .getCommonService().findByPage(getModel(),
                    getPageInfo());
            log.debug( "list size=" + this .pageList.getList().size());
            this .setSuccess( true );
            this .setMsg( "成功" );
            return SUCCESS;
        } catch (Exception e) {
            log.error( "list error." + e.getMessage(), e);
            throw e;
        }
    }
   
   
}


CmsJsonAction代码如下

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@ParentPackage ( "json" )
@Results ({
        /**
         * 默认返回Result,如果对象有关联对象,请在子类中重写该Result
         */
        @Result (name = Action.SUCCESS, type = "json" , params = { "includeProperties" , "success,msg,list.*,pageList.*" }),
        @Result (name = Action.INPUT, type = "json" , params = { "includeProperties" , "success,msg,model.*" }),
        @Result (name = CmsJsonAction.ERROR_INFO, type = "redirectAction" ,params={
                "actionName" , "result-code" ,
                "namespace" , "/system" ,
                "method" , "findError" ,
                "resultCode" , "${resultCode}"
        }),       
        @Result (name = CmsJsonAction.LIST, type = "json" , params = { "includeProperties" , "success,msg,list.*" }),
        @Result (name = CmsJsonAction.INFO, type = "json" , params = { "includeProperties" , "resultCode,success,msg" }) })
public abstract class CmsJsonAction<T,PK extends Serializable> extends ActionSupport implements
        Preparable {
    private static final long serialVersionUID = 1L;
 
    protected Log log = LogFactory.getLog(getClass());
    /**
     * 返回消息.如:{success:true,msg:"成功"}
     */
    public static final String INFO = "info" ;
    /**
     * 返回该action的主页面
     */
    public static final String INDEX = "index" ;
    /**
     * 根据resultCode查询错误消息并返回
     */
    public static final String ERROR_INFO = "errorInfo" ;
    /**
     * 查询全部
     */
    public static final String LIST = "list" ;
......


extjs前台界面如下

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Ext.onReady(function() {
    Ext.QuickTips.init(); // 初始化提示组件
 
    // 查询工具条
    var searchToolbar = new Ext.Toolbar({
        items : [ "用户号码" ,{                   
                    id : 'model.mdn' ,
                    maxLength : 15 ,
                    xtype : "textfield" ,                   
                    maskRe:/\d/,
                    regex:/^[ 0 - 9 ]{ 0 , 11 }$/,
                    emptyText: '只能输入数字' ,
                    listeners:{
                        'specialKey' :function(field,e){
                            onSearchFieldEnter(field,e);
                        }
                    }
                }, '-' , '日期' , '-' ,{
                    xtype : 'datefield' ,
                    id : 'model.joinTime' ,
                    format: "Y-m-d" ,                                   
                    listeners:{
                        'specialKey' :function(field,e){
                            onSearchFieldEnter(field,e);
                        }
                    }
                }, '-' ,{
                    xtype : 'button' ,
                    text : "查询" ,
                    iconCls : 'search' ,
                    listeners : {
                        "click" : function() {
                            grid.onRefresh();
                        }
                    }
                }]
    });
    // 列表部分
    var gridStructure = [{header: 'id' ,
                name: "id" ,
                width: 10 ,
                hidden: true ,
                sortable: true },{
                header : '活动ID' ,
                name : "activityId" ,
                width: 100 },
             {
                header : '总数' ,
                name : "mdn" ,
                width: 200
               
                //sortable : true
            }];
    /**
     * 在条件输入框上回事执行查询功能
     * @param {Ext.form.textfield} field
     * @param {EventObject} e
     */
    var onSearchFieldEnter = function(field,e){
        if (e.getKey() == Ext.EventObject.ENTER) {
            grid.onRefresh();
        }
    };
    var form = new Ext.ux.form.BasicTableForm({
                id : 'saveOrUpdateForm' ,
                layoutConfig : {
                    columns : 1
                    // 每一行的表单数
                },
                autoHeight : true ,
                waitMsgTarget : true ,
                reader : new Ext.data.JsonReader({
                            successProperty : 'success' ,
                            root : 'model' ,
                              idProperty : 'id'
                        }, [{
                                    name : 'model.id' ,
                                    mapping : 'id'
                                }, // custom mapping
                                {
                                    name: 'model.activityId' ,
                                    mapping: 'activityId'
                                },
                                {
                                    name: 'model.mdn' ,                               
                                    mapping: 'mdn'
                                }])
           
            });
 
 
           
    var grid = new Ext.ux.grid.CrudGrid({
                entityName : '显示页面' ,
                entityCode : 'model' ,
                region: 'center' ,
                structure : gridStructure,
                url : ctx + '/system/activity-sum!list.action' ,
                defaultSortField : 'id' ,
                keyField : 'id' ,
                deleteUrl : ctx+ '/system/activity-sum!delete.action' ,
                saveOrUpdateUrl : ctx+ '/system/activity-sum!save.action' ,
                formLoadUrl : ctx+ '/system/activity-sum!input.action' ,
                // 设置高度为页面页面高度
                height : document.body.clientHeight,
                searchTbar : searchToolbar,
                saveOrUpdateForm : form,
                //saveOrUpdateWindowWidth : 350,
                //删除时,接收ids的参数名,不设置时默认为keyField+'s'
                //deleteKeyField:'ids'
                rowActionsShow: false ,   //操作列显示
                dblclickUpdate: false //行双击事件
                showAddBtn: false //新增按钮
                showDeleteBtn: false //删除按钮
            });   
    this .grid = grid;   
   
    var viewport = new Ext.Viewport({
        layout: 'border' ,
        applyTo:Ext.getBody(),
        items:[grid]
    });   
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值