package com.consum.base.core.utils;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.HashMap;
|
import java.util.Map;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.jdbc.core.RowMapper;
|
|
/**
|
* @author asus
|
* @version 1.0
|
* @description: Mapper map工具类</p> 包含驼峰格式和列名别名
|
* @date 2023/11/11 14:40
|
*/
|
@Slf4j
|
public class MapperUtil implements RowMapper<Map<String, Object>> {
|
|
@Override
|
public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
|
Map<String, Object> row = new HashMap<>();
|
int columnCount = rs.getMetaData().getColumnCount();
|
for (int i = 1; i <= columnCount; i++) {
|
String columnLabel = rs.getMetaData().getColumnLabel(i);
|
String columnName = columnLabel.contains("_") ? MapUtils.underlineToCamel(columnLabel)
|
: (Character.isUpperCase(columnLabel.charAt(0)) ? columnLabel.toLowerCase()
|
: columnLabel);
|
Object columnValue = rs.getObject(i);
|
row.put(columnName, columnValue);
|
}
|
return row;
|
}
|
}
|