public <T> List<T> getGAPListByDate(String webDataSource, String webPlatType, Date startDt, Date endDt, String tableName, Class<T> cls) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String greDate = ">=STR_TO_DATE('" + sf.format(startDt) + "','%Y-%m-%d %H:%i:%s')";
String lesDate = "<STR_TO_DATE('" + sf.format(endDt) + "','%Y-%m-%d %H:%i:%s')";
StringBuffer sql = new StringBuffer("select * from ");
sql.append(tableName + " ");
sql.append("where (");
sql.append("(create_date" + greDate + " AND create_date" + lesDate + ") or ");
sql.append("(update_date" + greDate + " AND update_date" + lesDate + ") or ");
sql.append("(delete_date" + greDate + " AND delete_date" + lesDate + ") or ");
sql.append("(in_date" + greDate + " AND in_date" + lesDate + ")");
sql.append(") ");
//if (ConstantUtil.SEAL_TABLE_NAME.equals(tableName)) {
// sql.append("and ").append("( ").append("vertify_type IN ('1','2')").append(") ");
//}
//logger.info("query sql=" + sql);
Long st = System.currentTimeMillis();
Query query = this.getSession().createSQLQuery(sql.toString()).addEntity(cls);
List<T> list = query.list();
Long end = System.currentTimeMillis();
//logger.info("use time/s:"+(end-st)/1000);
return list;
}
//引用
List<Seal> list = getGAPListByDate(GAPFaceMessageCode.WEB_DATA_SOURCE, GAPFaceMessageCode.WEB_PLAT_TYPE,标签:lesDate,date,String,greDate,案例,sql,泛型,方法,append From: https://www.cnblogs.com/sung1024/p/16638733.html
startDt, endDt, ConstantUtil.SEAL_TABLE_NAME, Seal.class);