NutzCN Logo
问答 如何用Sqls.create(sqlstr)自定义SQL来实现分页查询视图?
发布于 2690天前 作者 qq_7fafbecc 1771 次浏览 复制 上一个帖子 下一个帖子
标签:
    	List<ProjectProgress> list = new ArrayList<ProjectProgress>();
		String sqlstr2 = "select a.*,"
				+ "(select b.codename from CODEMNG b where b.CODETYPE = 'PROGRESSSTEP' and b.CODE = a.PROGRESSSTEP) PROGRESSSTEPTEXT,"
				+ "(select b.DISPLAYNAME from SYSUSER b where b.userid = a.userid) username,"
				+ "(select b.codename from CODEMNG b where b.CODETYPE = 'PROGRESSPLACE' and b.CODE = a.PROGRESSPLACE) PROGRESSPLACETEXT "
				+ "from V_PROJECTPROGRESS_TJ a where tripId = '"+tripList.get(0).getTripId()+"' and userId = '"+user.getUserId()+"'  ";
		long total = Daos.queryCount(dao,sqlstr2);
		sqlstr2 = sqlstr2 + " order by a.workDate desc";
		Sql sql2 = Sqls.create(sqlstr2);
		//分页
		sql2.setPager(pager);
		sql2.setParam("userId", user.getUserId());
		sql2.setParam("tripId", tripList.get(0).getTripId());
		
		sql2.setCallback(Sqls.callback.entities());
		sql2.setEntity(dao.getEntity(ProjectProgress.class));
		dao.execute(sql2);
		//设置总记录数
		pager.setRecordCount((int)total);
		list = sql2.getList(ProjectProgress.class);
		//return list;
		
        returnMap.put("total", pager.getRecordCount());
        returnMap.put("rows", list);
        return returnMap; 

关键点:
一、要能够自定义SQL
二、是查询数据库视图
三、要能够分页

3 回复
sql2.setEntity(dao.getEntity(ProjectProgress.class));

这里面也要有个JAVA实体类,对应数据库视图吗?

取决于用何种回调,例如records就不需要咯

添加回复
请先登陆
回到顶部