Commit a68b1a4d authored by Zhang's avatar Zhang

Upload New File

parent 8bb2333e
package com.mybatis.handle;
package com.mybatis.handle;
import com.mybatis.model.Context;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@MappedTypes(Context.class)
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ContentTypeHandler extends BaseTypeHandler<Context> {
@Override
public void setNonNullParameter(PreparedStatement preparedStatement, int i, Context context, JdbcType jdbcType) throws SQLException {
String str = JSONObject.toJSONString(context);
preparedStatement.setString(i,str);
}
@Override
public Context getNullableResult(ResultSet resultSet, String s) throws SQLException {
String string = resultSet.getString(s);
return JSONObject.parseObject(string, Context.class);
}
@Override
public Context getNullableResult(ResultSet resultSet, int i) throws SQLException {
String string = resultSet.getString(i);
return JSONObject.parseObject(string, Context.class);
}
@Override
public Context getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
String string = callableStatement.getString(i);
return JSONObject.parseObject(string, Context.class);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment