We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
例如mysql的字段为:
type enum('project','task','execution') NOT NULL DEFAULT 'project', deleted enum('0','1') NOT NULL DEFAULT '0',
type
deleted
多谢
The text was updated successfully, but these errors were encountered:
没有
Sorry, something went wrong.
研究了一下, 使用一个定制的typeHandler可以实现:
/**
Type Handler for like "Status" Enum String field.
@author Felix Zhang 2024-05-06 10:30
@Version 1.0.0 */ @MappedJdbcTypes({JdbcType.OTHER}) @MappedTypes({String.class}) @slf4j public class StringEnumTypeHandler extends BaseTypeHandler {
@OverRide public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { log.info("String: " + parameter); ps.setString(i, parameter); }
@OverRide public T getNullableResult(ResultSet rs, String columnName) throws SQLException { log.info("value: " + rs.getString(columnName)); return (T) rs.getString(columnName); }
@OverRide public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return (T) rs.getString(columnIndex); }
@OverRide public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { return (T) cs.getString(columnIndex); }
}
然后在mybatis配置里配置 type-handlers-package 为你的包名
然后Java里使用String类型, Jdbc类型就用Other就可以.
Java里也可以用 Integer, 不过就要另外写一个typeHandler了.
No branches or pull requests
例如mysql的字段为:
type
enum('project','task','execution') NOT NULL DEFAULT 'project',deleted
enum('0','1') NOT NULL DEFAULT '0',多谢
The text was updated successfully, but these errors were encountered: