New file |
| | |
| | | package com.dy.common.mybatis; |
| | | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import org.apache.ibatis.type.BaseTypeHandler; |
| | | import org.apache.ibatis.type.JdbcType; |
| | | |
| | | import java.sql.CallableStatement; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | public class JsonTypeHandler extends BaseTypeHandler<JSONObject> { |
| | | @Override |
| | | public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException { |
| | | ps.setString(i, parameter.toString()); |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException { |
| | | String json = rs.getString(columnName); |
| | | return JSONUtil.parseObj(json); |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException { |
| | | String json = rs.getString(columnIndex); |
| | | return JSONUtil.parseObj(json); |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { |
| | | String json = cs.getString(columnIndex); |
| | | return JSONUtil.parseObj(json); |
| | | } |
| | | } |