diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index 84867940ef6c..cc744def31bb 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -524,6 +524,9 @@ public static String convertPropertyNameToUnderscoreName(@Nullable String name) if (Character.isUpperCase(c)) { result.append('_').append(Character.toLowerCase(c)); } + else if (Character.isDigit(c) && !Character.isDigit(name.charAt(i - 1))) { + result.append('_').append(c); + } else { result.append(c); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java index 502b50891f57..ac4717bc9deb 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/JdbcUtilsTests.java @@ -55,6 +55,14 @@ void convertUnderscoreNameToPropertyName() { assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("yOUR_nAME")).isEqualTo("yourName"); assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("a_name")).isEqualTo("AName"); assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("someone_elses_name")).isEqualTo("someoneElsesName"); + assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("some_name_with_1_digit")).isEqualTo("someNameWith1Digit"); } + @Test + void convertPropertyNameToUnderscoreName() { + assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("AName")).isEqualTo("a_name"); + assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someoneElsesName")).isEqualTo("someone_elses_name"); + assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someNameWith1Digit")).isEqualTo("some_name_with_1_digit"); + assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someNameWith12Number")).isEqualTo("some_name_with_12_number"); + } }