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", nowTime.getMonthValue())); //判斷表是否存在 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<TDtGnss> tDtGnsses = dtGnssService.selectByExample(gnssExample);

//也可以通過${}直接拼接在表名稱后面
select count(*) from t_dt_sensor${tableName}

按月創建表鏈接:https://www.cnblogs.com/smile-wei/p/6424671.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM