Skip to content

Commit c86a2eb

Browse files
committed
feat: typeHandler 添加 mapping 方法
1 parent 5f5c2bb commit c86a2eb

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

common/src/main/java/top/cadecode/uniboot/common/mybatis/handler/BoolToIntTypeHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.cadecode.uniboot.common.mybatis.handler;
22

3+
import cn.hutool.core.util.ObjectUtil;
34
import org.apache.ibatis.type.BaseTypeHandler;
45
import org.apache.ibatis.type.JdbcType;
56
import org.apache.ibatis.type.MappedJdbcTypes;
@@ -21,10 +22,14 @@
2122
public class BoolToIntTypeHandler extends BaseTypeHandler<Boolean> {
2223

2324
/**
24-
* 用于 mybatis plus update set mapping 参数指定 typeHandler 为 BoolToIntTypeHandler
25+
* 用于 mybatis plus update set mapping 参数指定 typeHandler
2526
*/
2627
public static final String MAPPING = "typeHandler=BoolToIntTypeHandler";
2728

29+
public static Integer mapping(Boolean o) {
30+
return ObjectUtil.isNull(o) ? null : (o ? 1 : 0);
31+
}
32+
2833
@Override
2934
public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException {
3035
if (parameter) {

common/src/main/java/top/cadecode/uniboot/common/mybatis/handler/ObjToStrTypeHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
public class ObjToStrTypeHandler extends BaseTypeHandler<Object> {
2424

2525
/**
26-
* 用于 mybatis plus update set mapping 参数指定 typeHandler 为 ObjToStrTypeHandler
26+
* 用于 mybatis plus update set mapping 参数指定 typeHandler
2727
*/
2828
public static final String MAPPING = "typeHandler=ObjToStrTypeHandler";
2929

30+
public static String mapping(Object o) {
31+
return JacksonUtil.toJson(o);
32+
}
33+
3034
private final Class<?> type;
3135

3236
public ObjToStrTypeHandler(Class<?> type) {

0 commit comments

Comments
 (0)