|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
37 | 37 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
38 | 38 | import org.springframework.jdbc.support.JdbcUtils;
|
39 | 39 | import org.springframework.util.Assert;
|
| 40 | +import org.springframework.util.StringUtils; |
40 | 41 |
|
41 | 42 | /**
|
42 | 43 | * {@link RowMapper} implementation that converts a row into a new instance
|
@@ -163,18 +164,19 @@ protected void initialize(Class<T> mappedClass) {
|
163 | 164 | * @return the converted name
|
164 | 165 | */
|
165 | 166 | private String underscoreName(String name) {
|
| 167 | + if (!StringUtils.hasLength(name)) { |
| 168 | + return ""; |
| 169 | + } |
166 | 170 | StringBuilder result = new StringBuilder();
|
167 |
| - if (name != null && name.length() > 0) { |
168 |
| - result.append(name.substring(0, 1).toLowerCase()); |
169 |
| - for (int i = 1; i < name.length(); i++) { |
170 |
| - String s = name.substring(i, i + 1); |
171 |
| - if (s.equals(s.toUpperCase())) { |
172 |
| - result.append("_"); |
173 |
| - result.append(s.toLowerCase()); |
174 |
| - } |
175 |
| - else { |
176 |
| - result.append(s); |
177 |
| - } |
| 171 | + result.append(name.substring(0, 1).toLowerCase()); |
| 172 | + for (int i = 1; i < name.length(); i++) { |
| 173 | + String s = name.substring(i, i + 1); |
| 174 | + String slc = s.toLowerCase(); |
| 175 | + if (!s.equals(slc)) { |
| 176 | + result.append("_").append(slc); |
| 177 | + } |
| 178 | + else { |
| 179 | + result.append(s); |
178 | 180 | }
|
179 | 181 | }
|
180 | 182 | return result.toString();
|
|
0 commit comments