key转换为大写/小写

重写ColumnMapRowMapper

  1. @TestInstance(TestInstance.Lifecycle.PER_CLASS)
  2. public class JdbcTests {
  3. JdbcTemplate jdbcTemplate = new JdbcTemplate();
  4. @BeforeAll
  5. public void before() {
  6. MysqlDataSource dataSource = new MysqlDataSource();
  7. dataSource.setPort(3306);
  8. dataSource.setUser("root");
  9. dataSource.setPassword("@@@@@");
  10. dataSource.setServerName("39.97.243.43");
  11. jdbcTemplate.setDataSource(dataSource);
  12. }
  13. @Test
  14. @SneakyThrows
  15. public void a1() {
  16. String sql = "select * from test.demo";
  17. List<Map<String, Object>> query = jdbcTemplate.query(sql, new ColumnMapRowMapper(){
  18. protected String getColumnKey(String columnName) {
  19. return columnName.toUpperCase();
  20. }
  21. });
  22. System.out.println(query);
  23. }
  24. }