您的当前位置:首页正文

MYSQL通过Example来拼接表名称查询

2024-01-14 来源:意榕旅游网
MYSQL通过Example来拼接表名称查询

StringBuilder tableName = new StringBuilder(); //拼接表名

tableName.append(TdwTableNameEnums.GNSS.getValue()); tableName.append(\"_\").append(appCategory.getDictCode());

tableName.append(\"_\").append(nowTime.getYear()).append(String.format(\"%02d\ //判断表是否存在

if (!dtCommonService.whetherExistsTableName(tableSchema, tableName.toString())) { return debugInfoVOList; }

//封装查询条件

TDtGnssExample gnssExample = new TDtGnssExample(tableName.toString()); TDtGnssExample.Criteria criteria = gnssExample.createCriteria(); criteria.andAnchorIdEqualTo(monitorAnchor.getAnchorId()); criteria.andTimestampGreaterThanOrEqualTo(startTime); criteria.andTimestampLessThanOrEqualTo(nowTime); gnssExample.setOrderByClause(\"timestamp\");//按⽉查询不同⽉份的表数据

List tDtGnsses = dtGnssService.selectByExample(gnssExample);//也可以通过${}直接拼接在表名称后⾯

select count(*) from t_dt_sensor${tableName}

因篇幅问题不能全部显示,请点此查看更多更全内容