ExtJs+SSH框架数据显示在前台的问题
我要进行一个分组统计的功能,查询一张数据库表,然后把它显示在前台。但数据库表里面是没有相应的这个字段的。我先贴代码吧。xml代码:
<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>
持久化的代码:
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这个字段和统计的数量。
我查数据库这层代码:
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的代码如下:
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代码如下
@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前台界面如下
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]
});
});
数据可以查的出啦,但是显示不了在前台,这是怎么回事的,是不是前端哪里有错误呢,或者要怎么改呢。
补充:Java , Java EE