Skip to content

Commit 8c1d2f3

Browse files
author
zhangrongfan
committed
Fix handler
1 parent 1b6c8b6 commit 8c1d2f3

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

mybatis-boost-core/src/main/java/cn/mybatisboost/json/JsonTypeHandler.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
import java.sql.SQLException;
1414

1515
@MappedTypes(Property.class)
16-
public class JsonTypeHandler extends BaseTypeHandler<Property<?>> {
16+
public class JsonTypeHandler extends BaseTypeHandler<Object> {
1717

1818
static ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
1919

2020
@Override
21-
public void setNonNullParameter(PreparedStatement ps, int i, Property<?> parameter, JdbcType jdbcType)
21+
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
2222
throws SQLException {
2323
try {
24-
if (parameter.isPresent()) {
25-
ps.setString(i, objectMapper.writeValueAsString(parameter.get()));
24+
Property<?> property = (Property<?>) parameter;
25+
if (property.isPresent()) {
26+
ps.setString(i, objectMapper.writeValueAsString(property.get()));
2627
} else {
2728
ps.setObject(i, null);
2829
}
@@ -32,17 +33,17 @@ public void setNonNullParameter(PreparedStatement ps, int i, Property<?> paramet
3233
}
3334

3435
@Override
35-
public Property<?> getNullableResult(ResultSet rs, String columnName) throws SQLException {
36-
return Property.ofNullable(rs.getString(columnName));
36+
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
37+
return rs.getString(columnName);
3738
}
3839

3940
@Override
40-
public Property<?> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
41-
return Property.ofNullable(rs.getString(columnIndex));
41+
public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
42+
return rs.getString(columnIndex);
4243
}
4344

4445
@Override
45-
public Property<?> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
46-
return Property.ofNullable(cs.getString(columnIndex));
46+
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
47+
return cs.getString(columnIndex);
4748
}
4849
}

mybatis-boost-test/src/main/java/cn/mybatisboost/test/Project.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cn.mybatisboost.test;
22

3-
import cn.mybatisboost.support.Property;
3+
import java.util.Optional;
44

55
public class Project {
66

@@ -10,7 +10,7 @@ public class Project {
1010
private String license;
1111
private String scm;
1212
private String developer;
13-
private Property<Website> website = Property.empty();
13+
private Website website;
1414

1515
public Project() {
1616
}
@@ -21,7 +21,7 @@ public Project(String groupId, String artifactId, String license, String scm, St
2121
this.license = license;
2222
this.scm = scm;
2323
this.developer = developer;
24-
this.website = Property.ofNullable(website);
24+
this.website = website;
2525
}
2626

2727
public Integer getId() {
@@ -79,12 +79,12 @@ public Project setDeveloper(String developer) {
7979
}
8080

8181

82-
public Property<Website> getWebsite() {
83-
return website;
82+
public Optional<Website> getWebsite() {
83+
return Optional.ofNullable(website);
8484
}
8585

8686
public void setWebsite(Website website) {
87-
this.website = Property.ofNullable(website);
87+
this.website = website;
8888
}
8989

9090
@Override

0 commit comments

Comments
 (0)