2024-05-17 10:41

batchSize可以调整下大小 一般500-1000

2024-05-17 10:13

@杜福忠 这个参数会极大提高执行速度

2023-08-14 15:03

@杜福忠 还有比较省事的做法就是利用druid提供的PagerUtils.count PagerUtils.limit 方法来代替jfinal原本提供的生成count sql 和分页取数据的sql

2023-08-08 15:32

有可能是线上环境缺少某些字体,poi生成excel对某些字体有要求

2023-06-28 11:39

@JFinal import com.jfinal.plugin.activerecord.*;

import java.sql.*;
import java.util.List;
import java.util.Map;

/**
* @date 2023/6/28 09:57
*/
public class CustomDbPro extends DbPro {
public CustomDbPro(String configName) {
super(configName);
}

@SuppressWarnings("rawtypes")
@Override
protected int[] batch(Config config, Connection conn, String sql, String columns, List list, int batchSize) throws SQLException {
if (list == null || list.size() == 0)
return new int[0];
Object element = list.get(0);
if (!(element instanceof Record) && !(element instanceof Model))
throw new IllegalArgumentException("The element in list must be Model or Record.");
if (batchSize < 1)
throw new IllegalArgumentException("The batchSize must more than 0.");
boolean isModel = element instanceof Model;

String[] columnArray = columns.split(",");
for (int i = 0; i < columnArray.length; i++)
columnArray[i] = columnArray[i].trim();

boolean isInTransaction = config.isInTransaction();
int counter = 0;
int pointer = 0;
int size = list.size();
int[] result = new int[size];
try (PreparedStatement pst = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
for (int i = 0; i < size; i++) {
Map map = isModel ? CPI.getAttrs((Model) list.get(i)) : ((Record) list.get(i)).getColumns();
for (int j = 0; j < columnArray.length; j++) {
Object value = map.get(columnArray[j]);
if (value instanceof java.util.Date) {
if (value instanceof java.sql.Date) {
pst.setDate(j + 1, (java.sql.Date) value);
} else if (value instanceof java.sql.Timestamp) {
pst.setTimestamp(j + 1, (java.sql.Timestamp) value);
} else {
// Oracle、SqlServer 中的 TIMESTAMP、DATE 支持 new Date() 给值
java.util.Date d = (java.util.Date) value;
pst.setTimestamp(j + 1, new java.sql.Timestamp(d.getTime()));
}
} else {
pst.setObject(j + 1, value);
}
}
pst.addBatch();
if (++counter >= batchSize) {
counter = 0;
int[] r = pst.executeBatch();
if (!isInTransaction)
conn.commit();
//for (int j : r) {
// result[pointer++] = j;
//}
ResultSet rs = pst.getGeneratedKeys();
while (rs.next()) {
result[pointer++] = rs.getInt(1);
}
}
}
if (counter != 0) {
int[] r = pst.executeBatch();
if (!isInTransaction) {
conn.commit();
}
//for (int i : r) {
// result[pointer++] = i;
//}
ResultSet rs = pst.getGeneratedKeys();
while (rs.next()) {
result[pointer++] = rs.getInt(1);
}
}
return result;
}
}

}
实测这样重写后可以获取批量插入的主键列表

2023-06-27 18:32

@JFinal 貌似重点在 PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) 这里

2023-06-27 18:28

@JFinal 貌似JdbcTemplate可以https://blog.csdn.net/allway2/article/details/127212115,jfinal中能否搞定?

2023-04-06 12:49

@JFinal 当http status code 不为200时(例如404) 获取 in = conn.getInputStream();时就会抛出java.io.FileNotFoundException这个异常,此时应该去in = conn.getErrorStream();获取输入流

2023-04-05 19:06

@杜福忠 Charsert是否拼写错误?

2023-03-08 09:32

开源了吗

2023-03-04 21:45

@zeroabc 你为啥要把项目安装到本地仓库,建议去补下maven基础知识

2023-02-26 21:25

直接docker 不好吗

2023-02-16 16:38

@杜福忠 他想实现的应该是容器层面的日志记录并且支持pattern配置记录内容,类似%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %D ms

2023-02-16 16:27

new FileInputStream(getFile())不可以吗?

2023-02-15 09:51

@zlsj80 主要抄springboot相关的实现