mybatis 枚举 EnumTypeHandler如何使用
1个回答
展开全部
<result property="app_ver_current" column="APP_VER_CURRENT"
typeHandler="com.andson.kb.server.enums.handler.YesNoEnumHandler" />
public class YesNoEnumHandler implements TypeHandler<YesNoEnum> {
@Override
public YesNoEnum getResult(ResultSet rs, String columnLabel) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(rs.getInt(columnLabel));
}
@Override
public YesNoEnum getResult(ResultSet rs, int columnIndex) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(rs.getInt(columnIndex));
}
@Override
public YesNoEnum getResult(CallableStatement cs, int parameterIndex) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(cs.getInt(parameterIndex));
}
@Override
public void setParameter(PreparedStatement ps, int columnIndex, YesNoEnum yesNoEnum, JdbcType jdbcType)
throws SQLException {
// TODO Auto-generated method stub
ps.setInt(columnIndex, yesNoEnum.getValue());
}
}
typeHandler="com.andson.kb.server.enums.handler.YesNoEnumHandler" />
public class YesNoEnumHandler implements TypeHandler<YesNoEnum> {
@Override
public YesNoEnum getResult(ResultSet rs, String columnLabel) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(rs.getInt(columnLabel));
}
@Override
public YesNoEnum getResult(ResultSet rs, int columnIndex) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(rs.getInt(columnIndex));
}
@Override
public YesNoEnum getResult(CallableStatement cs, int parameterIndex) throws SQLException {
// TODO Auto-generated method stub
return YesNoEnum.valueOf(cs.getInt(parameterIndex));
}
@Override
public void setParameter(PreparedStatement ps, int columnIndex, YesNoEnum yesNoEnum, JdbcType jdbcType)
throws SQLException {
// TODO Auto-generated method stub
ps.setInt(columnIndex, yesNoEnum.getValue());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询