系统配置修改
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package org.xyzh.common.utils.json;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @description FastJSON2 JSONObject 类型处理器
|
||||
* @filename FastJson2TypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2025-12-09
|
||||
*/
|
||||
@MappedTypes({JSONObject.class})
|
||||
public class FastJson2TypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i, parameter.toJSONString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonString = rs.getString(columnName);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonString = rs.getString(columnIndex);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonString = cs.getString(columnIndex);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
private JSONObject parseToJSONObject(String jsonString) {
|
||||
if (jsonString == null || jsonString.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parseObject(jsonString);
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,返回一个空的JSONObject
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user