码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis中select语句字段大小写问题

时间:2015-01-30 19:46:34      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

我用的mybatis3.0.5

如果你用的mybatis3.0.5的话就会存在这个问题(其他版本我不知道),我以解决,改版后的mybatis-3.0.5.jar提供下载,替换项目中就好!

//org.apache.ibatis.executor.resultset.FastResultSetHandler中第298行代码,
mybatis3.0.5源代码为:

protected void loadMappedAndUnmappedColumnNames(ResultSet rs, ResultMap resultMap, List<String> mappedColumnNames, List<String> unmappedColumnNames) throws SQLException {
    mappedColumnNames.clear();
    unmappedColumnNames.clear();
    final ResultSetMetaData rsmd = rs.getMetaData();
    final int columnCount = rsmd.getColumnCount();
    final Set<String> mappedColumns = resultMap.getMappedColumns();
    for (int i = 1; i <= columnCount; i++) {
      final String columnName = configuration.isUseColumnLabel() ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
      final String upperColumnName = columnName.toUpperCase(Locale.ENGLISH);
      if (mappedColumns.contains(upperColumnName)) {
        mappedColumnNames.add(upperColumnName);
        mappedColumnNames.add(columnName);
      } else {
        unmappedColumnNames.add(upperColumnName);
        unmappedColumnNames.add(columnName);
      }
    }
  }

修改后的代码为:

protected void loadMappedAndUnmappedColumnNames(ResultSet rs, ResultMap resultMap, List<String> mappedColumnNames, List<String> unmappedColumnNames) throws SQLException {
    mappedColumnNames.clear();
    unmappedColumnNames.clear();
    final ResultSetMetaData rsmd = rs.getMetaData();
    final int columnCount = rsmd.getColumnCount();
    final Set<String> mappedColumns = resultMap.getMappedColumns();
    for (int i = 1; i <= columnCount; i++) {
      final String columnName = configuration.isUseColumnLabel() ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
      //final String upperColumnName = columnName.toUpperCase(Locale.ENGLISH);
      if (mappedColumns.contains(upperColumnName)) {
        //mappedColumnNames.add(upperColumnName);
        mappedColumnNames.add(columnName);
      } else {
        //unmappedColumnNames.add(upperColumnName);
        unmappedColumnNames.add(columnName);
      }
    }
  }

 提供编译好的jar替换就可以 下载地址:http://pan.baidu.com/s/1pJyqavh

 

mybatis中select语句字段大小写问题

标签:

原文地址:http://my.oschina.net/Thinkeryjgfn/blog/373771

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!