mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-13 15:55:42 +08:00
fix(mybatis): jsonb 类型处理器兼容空字符串, 避免写入报 invalid input syntax for type json
This commit is contained in:
@@ -10,6 +10,7 @@ import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
/// # PostgreSQL jsonb 字符串类型处理器。
|
||||
///
|
||||
@@ -27,6 +28,11 @@ public class JsonbStringTypeHandler extends BaseTypeHandler<String> {
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
// 空字符串不是合法 JSON, jsonb 列应存 NULL
|
||||
if (parameter == null || parameter.isBlank()) {
|
||||
ps.setNull(i, Types.OTHER);
|
||||
return;
|
||||
}
|
||||
PGobject jsonObject = new PGobject();
|
||||
jsonObject.setType("jsonb");
|
||||
jsonObject.setValue(parameter);
|
||||
|
||||
Reference in New Issue
Block a user