查询表里的字段,然后以字符串的格式输出,再用分隔符分开,成对出现

public Page queryTerminalForPage(String subMerid,String terminalBeginNo,String terminalEndNo, int start, int pageSize)
			throws BusiException, Exception {
		if (StringUtil.isNullorEmpty(subMerid)) {
			throw new BusiException("获取工单的终端的时,分店id不能为空!");
		}
		Criteria criteria = taskDao.createCriteria(TM03Terminal.class);
		CriteriaUtil.add(criteria, terminalBeginNo, "terminalNo", Operation.GE);
		CriteriaUtil.add(criteria, terminalEndNo, "terminalNo", Operation.LE);
		criteria.add(Restrictions.eq("submerId", subMerid));

		Page page = taskDao.queryCriteriaForPage(criteria, start, pageSize);
		if (page != null) {
		    String  getDevice = "select  twt121.model ||','||twt121.SERIAL_NO||'&;'||twt122.model ||'," +
		    		"'||twt122.SERIAL_NO||'&;'||twt123.model ||','||twt123.SERIAL_NO" +
		    		"||'&;'||twt124.model ||','||twt124.SERIAL_NO||'&;'||twt125.model ||','||twt125.SERIAL_NO " +
		    		"from t_m03_terminal tm03 " + 
		    		"left join t_wt10_device twt121 on twt121.terminal_id = tm03.id and twt121.device_type = 0 " + //--主机 
		    		"left join t_wt10_device twt122 on twt122.terminal_id = tm03.id and twt122.device_type = 1 " + //-- 密码键盘 
		    		"left join t_wt10_device twt123 on twt123.terminal_id = tm03.id and twt123.device_type = 2 " + //--手写板 
		    		"left join t_wt10_device twt124 on twt124.terminal_id = tm03.id and twt124.device_type = 3 " +//--SIM卡 
		    		"left join t_wt10_device twt125 on twt125.terminal_id = tm03.id and twt125.device_type = 4 " +//--读卡器 
		    		"where tm03.id = '%s'"; 
			List<TM03Terminal> termList = (List<TM03Terminal>) page.getResult();
			if (termList != null && termList.size() > 0) {
				for (TM03Terminal m03 : termList) {
				    String deviceString = StringUtil.getString(taskDao.findBySql(String.format(getDevice,m03.getId())));
				    String [] resultDevice = deviceString.split("&;");
				    m03.setViDevice0(resultDevice[0]);
				    m03.setViDevice1(resultDevice[1]);
				    m03.setViDevice2(resultDevice[2]);
				    m03.setViDevice3(resultDevice[3]);
				    m03.setViDevice4(resultDevice[4]);
					virtualField.setViTM03Terminal(m03);
				}
			}

		}
		return page;

	}

然后:在数据库里执行的语句:



 select
        * 
    from
        ( select
            twt121.model ||','||twt121.SERIAL_NO||'&;'||twt122.model ||','||twt122.SERIAL_NO||'&;'||twt123.model ||','||twt123.SERIAL_NO||'&;'||twt124.model ||','||twt124.SERIAL_NO||'&;'||twt125.model ||','||twt125.SERIAL_NO 
        from
            t_m03_terminal tm03 
        left join
            t_wt10_device twt121 
                on twt121.terminal_id = tm03.id 
                and twt121.device_type = 0 
        left join
            t_wt10_device twt122 
                on twt122.terminal_id = tm03.id 
                and twt122.device_type = 1 
        left join
            t_wt10_device twt123 
                on twt123.terminal_id = tm03.id 
                and twt123.device_type = 2 
        left join
            t_wt10_device twt124 
                on twt124.terminal_id = tm03.id 
                and twt124.device_type = 3 
        left join
            t_wt10_device twt125 
                on twt125.terminal_id = tm03.id 
                and twt125.device_type = 4 
        where
            tm03.id = '4028b2d251c239830151c351bf1000c4')










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值