import
;
import
;
import
;
import
;
import
;
import
;
import
;
public
class
JSONHandler
implements
TypeHandler<Object> {
/**
* json数据和类名的分隔符号
* */
private
static
final
char
SPLIT =
'/'
;
public
void
setParameter(PreparedStatement ps,
int
i, Object parameter,
JdbcType jdbcType)
throws
SQLException {
if
(parameter ==
null
){
(i,
null
);
return
;
}
String json = (parameter);
json = json + SPLIT + ().getName();
(i, json);
}
public
Object getResult(ResultSet rs, String columnName)
throws
SQLException {
String json = (columnName);
return
jsonToObject(json);
}
public
Object getResult(CallableStatement cs,
int
columnIndex)
throws
SQLException {
String json = (columnIndex);
return
jsonToObject(json);
}
/**
* json 转换成对象
* */
private
Object jsonToObject(String json){
if
(json ==
null
){
return
null
;
}
int
index = (SPLIT);
if
(index <
0
){
return
null
;
}
String key = (index +
1
, ());
json = (
0
, index);
Class<?> cls =
null
;
try
{
cls = (key);
}
catch
(ClassNotFoundException e) {
throw
new
RuntimeException(
"序列化成json时找不到指定的类"
, e);
}
Object ob = (json, cls);
return
ob;
}
}