如何通过mybatis中的注释处理我的班级类型?
我知道可以使用创建我的TypeHandler来转换mybatis中的类。 但是在TypeHandler方法中,我无法获取值上下文。
public class MyClass {
public String fieldA;
public String fieldB;
}
public class MyClassData {
@Annotation(fieldB="xxxxx")
MyClass myClass;
}
@MappedTypes(value = {MyClass.class})
public class MyClassTypeHandler extends BaseTypeHandler<MyClass> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, MyClass parameter, JdbcType jdbcType)
throws SQLException {
ps.setObject(i,parameter.fieldA);
}
@Override
public MyClass getNullableResult(ResultSet rs, String columnName) throws SQLException {
//How to get the convert context that from which Class and which Field.Then get the Annotation fieldB value?
return null;
}
@Override
public MyClass getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
return null;
}
@Override
public MyClass getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
return null;
}
}
预期:
@Override
public MyClass getNullableResult(ResultSet rs, String columnName) throws SQLException {
Annotation a;
MyClass value=new MyClass();
value.fieldA=rs.rs.getString(columnName);
value.feildB=a.fieldB;
return value;
}
有人可以给我一个建议吗?