多亏了乔凡尼(Giovanni)的回答,我注意到了类型处理程序的示例,然后从那里开始:
public class EmptyStringTypeHandler extends StringTypeHandler { @Override public String getResult(ResultSet rs, String columnName) throws SQLException { return unnulledString(super.getResult(rs, columnName)); } @Override public String getResult(ResultSet rs, int columnIndex) throws SQLException { return unnulledString(super.getResult(rs, columnIndex)); } @Override public String getResult(CallableStatement cs, int columnIndex) throws SQLException { return unnulledString(super.getResult(cs, columnIndex)); } private String unnulledString(String value) { return StringUtils.defaultString(value, ""); }}现在的界面是:
public interface DaoMapper { @Select({ "SELECT col1, col2, col3", "FROM my_table" }) @Results(value = { @Result(column = "col1", property = "col1", typeHandler = EmptyStringTypeHandler.class), @Result(column = "col2", property = "col2", typeHandler = EmptyStringTypeHandler.class), @Result(column = "col3", property = "col3", typeHandler = EmptyStringTypeHandler.class) }) List<linkedHashMap<String, ?>> getUntyped();}我应该补充一点,最大的好处是我可以在每条语句的每一列中指定它。为了更通用,最好按每个语句指定此名称。也许在将来的版本中?



