Browse Source

Fixed BeanPropertyRowMapper to only prefix actual upper-case letters with underscores

Issue: SPR-10547
pull/292/head
Juergen Hoeller 12 years ago committed by unknown
parent
commit
c8b071c89e
  1. 26
      spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

26
spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* {@link RowMapper} implementation that converts a row into a new instance * {@link RowMapper} implementation that converts a row into a new instance
@ -163,18 +164,19 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @return the converted name * @return the converted name
*/ */
private String underscoreName(String name) { private String underscoreName(String name) {
if (!StringUtils.hasLength(name)) {
return "";
}
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) { result.append(name.substring(0, 1).toLowerCase());
result.append(name.substring(0, 1).toLowerCase()); for (int i = 1; i < name.length(); i++) {
for (int i = 1; i < name.length(); i++) { String s = name.substring(i, i + 1);
String s = name.substring(i, i + 1); String slc = s.toLowerCase();
if (s.equals(s.toUpperCase())) { if (!s.equals(slc)) {
result.append("_"); result.append("_").append(slc);
result.append(s.toLowerCase()); }
} else {
else { result.append(s);
result.append(s);
}
} }
} }
return result.toString(); return result.toString();

Loading…
Cancel
Save