NutzCN Logo
问答 Sqls.create自定义sql,怎么把一个对象的属性(list<xx对象>)一起查出来?
发布于 2641天前 作者 qq_7fafbecc 1875 次浏览 复制 上一个帖子 下一个帖子
标签:

查询代码:

		Sql sql = Sqls.create(sqlstr);
		sql.setPager(pager);
		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(User.class));
		dao.execute(sql);
		rval = sql.getList(User.class);

实体对象User中有一个属性bindWards是List,其中存放的是另外一个实体对象Ward集合,怎么在SQL中实现连带这个bindWards一起在dao.execute(sql)中查出来?

	//绑定病区
    private List<Ward> bindWards;
3 回复

如果配了@Many的话,dao.queryByJoin

		String sqlstr = "select a.*,"
				+ "(select codeName from BLOOD_DICT_CODE b where b.CODETYPE = 'USERTYPE' and b.code = a.userType) USERTYPETEXT, "
				+ "(select codeName from BLOOD_DICT_CODE b where b.CODETYPE = 'USERSTATUS' and b.code = a.userStatus) USERSTATUSTEXT, "
				+ "(select deptName from BLOOD_DICT_DEPT b where b.deptCode = a.deptCode) DEPTCODETEXT, "
				+ "(select wardName from BLOOD_DICT_WARD b where b.wardCode = a.wardCode) WARDCODETEXT, "
				+ "(select jobName from BLOOD_DICT_JOB b where b.job = a.job and b.userType = a.userType) JOBTEXT "
				+ " from BLOOD_DICT_USER a where a.userType = '"+Globals.USERTYPE_NURSE+"' ";

我是这种语句SQL的,能用吗【@Many的话,dao.queryByJoin】?

那得自己写callback处理了

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