提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.mybatis.core.handler; |
H |
2 |
|
|
3 |
import com.alibaba.fastjson.JSON; |
|
4 |
import org.apache.ibatis.type.BaseTypeHandler; |
|
5 |
import org.apache.ibatis.type.JdbcType; |
|
6 |
|
|
7 |
import java.sql.CallableStatement; |
|
8 |
import java.sql.PreparedStatement; |
|
9 |
import java.sql.ResultSet; |
|
10 |
import java.sql.SQLException; |
|
11 |
|
|
12 |
public class MybatisHandler extends BaseTypeHandler<Object> { |
|
13 |
|
|
14 |
@Override |
|
15 |
public void setNonNullParameter(PreparedStatement preparedStatement, int i, Object o, JdbcType jdbcType) throws SQLException { |
|
16 |
preparedStatement.setString(i, JSON.toJSONString(o)); |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public Object getNullableResult(ResultSet resultSet, String s) throws SQLException { |
|
21 |
String sqlJson = resultSet.getString(s); |
|
22 |
if (null != sqlJson) { |
|
23 |
return JSON.parse(sqlJson); |
|
24 |
} |
|
25 |
return null; |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public Object getNullableResult(ResultSet resultSet, int i) throws SQLException { |
|
30 |
String sqlJson = resultSet.getString(i); |
|
31 |
if (null != sqlJson) { |
|
32 |
return JSON.parse(sqlJson); |
|
33 |
} |
|
34 |
return null; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public Object getNullableResult(CallableStatement callableStatement, int i) throws SQLException { |
|
39 |
String sqlJson = callableStatement.getString(i); |
|
40 |
if (null != sqlJson) { |
|
41 |
return JSON.parse(sqlJson); |
|
42 |
} |
|
43 |
return null; |
|
44 |
} |
|
45 |
} |