时间:2021-07-01 10:21:17 帮助过:18人阅读
2、继承ObjectJsonHandler
/** * @Author jijiecong * @Date 2021/4/20 11:49 * @Version 1.0 * @Description 评价扩展字段json处理器 */ public class EvaluationAttributesJsonHandler extends ObjectJsonHandler<EvaluationAttributesEntity> { public EvaluationAttributesJsonHandler() { super(EvaluationAttributesEntity.class); } }
二、List对象转JsonArray
1、继承BaseTypeHandler
覆盖setNonNullParameter(),getNullableResult(),getNullableResult(),getNullableResult()方法
** * ObjectJsonArrayHandler * JSONArray处理类 * * @version v1.0.0 * @date 2020/7/23 */ public class ObjectJsonArrayHandler<T> extends BaseTypeHandler<List<T>> { private final Class<T> clazz; public ObjectJsonArrayHandler(Class<T> clazz) { if (clazz == null) { throw new IllegalArgumentException("Type argument cannot be null"); } else { this.clazz = clazz; } } @Override public void setNonNullParameter(PreparedStatement ps, int i, List<T> ts, JdbcType jdbcType) throws SQLException { ps.setString(i, JSONArray.toJSONString(ts)); } @Override public List<T> getNullableResult(ResultSet rs, String s) throws SQLException { String jsonArrayStr = rs.getString(s); if (null != jsonArrayStr) { return JSONArray.parseArray(jsonArrayStr).toJavaList(clazz); } return null; } @Override public List<T> getNullableResult(ResultSet rs, int i) throws SQLException { String jsonArrayStr = rs.getString(i); if (null != jsonArrayStr) { return JSONArray.parseArray(jsonArrayStr).toJavaList(clazz); } return null; } @Override public List<T> getNullableResult(CallableStatement cs, int i) throws SQLException { String jsonArrayStr = cs.getString(i); if (null != jsonArrayStr) { return JSONArray.parseArray(jsonArrayStr).toJavaList(clazz); } return null; } }
2、继承ObjectJsonArrayHandler
/** * StringJsonArrayHandler * * @version v1.0.0 * @date 2020/8/11 */ public class StringJsonArrayHandler extends ObjectJsonArrayHandler<String> { public StringJsonArrayHandler(Class<String> clazz) { super(String.class); } }
json存数据库时处理器,jsonHandler/jsonArrayHandler
标签:覆盖 ali arrays jdb str ring div att resultset