自定义sql怎么使插入速度快起来?
12 回复
@wendal dao.execute(Sqls.create(sql))
@wendal 用自定义sql除了这种方法还有没有其他方法?
//根据id把一张表的记录增加到另一张表
public Object insertRecords(String byAllTableName, String userId, String allTableName, List<String> byFieldList, List<String> fieldList, String cndStr, String cndStrVal, Integer tableType) {
List<Map> list = getChangedetails(allTableName, userId.toString(), cndStr, cndStrVal, tableType);//增加的记录
if (list != null) {
List<Object> valueList = new ArrayList<>();//把值放到集合中
for (Object value : list.get(0).values()) {
valueList.add(value);
}
StringBuilder sql = new StringBuilder();
sql.append("insert into $byAllTableName (");
for (int z = 0; z < byFieldList.size(); z++) {//遍历表中字段
sql.append("$byAllTableName." + byFieldList.get(z) + ",");
}
sql.deleteCharAt(sql.length() - 1);
sql.append(")select \t");
for (int z = 0; z < fieldList.size(); z++) {
sql.append("$allTableName." + fieldList.get(z) + ",");
}
sql.deleteCharAt(sql.length() - 1);
sql.append("\tfrom $allTableName where $allTableName.UserId=@userId");
if (tableType == 2) {//从表
sql.append("\tand $cndStr=@cndStrVal");
}
Sql sqls = Sqls.create(sql.toString());
sqls.params().set("userId", userId).set("cndStrVal", cndStrVal);
sqls.vars().set("byAllTableName", byAllTableName).set("allTableName", allTableName).set("cndStr", cndStr);
dao.execute(sqls);
}
@wendal 就是两表数据同步
@wendal 好吧,看来只能从其他地方下手了
添加回复
请先登陆