← 피드로
1. Bean → Map
Method Description toSnakeCase(Object bean) Convert Bean to Map with snake_case keys; null values are omitted toSnakeCaseWithNull(Object bean) Convert Bean to Map with snake_case keys; null values are preserved toCamelCase(Object bean) Convert Bean to Map with camelCase keys; null values are omitted toCamelCaseWithNull(Object bean) Convert Bean to Map with camelCase keys; null values are preserved2. Map Key-Value Operations
Method Description removeNulls(Map map) Remove all entries with null values (mutates the original Map) filterNulls(Map map) Return a new Map with null-valued entries removed putEntries(Map map, Object… keyValues) Batch-put key-value pairs (mutates the original Map) withEntries(Map map, Object… keyValues) Batch-put key-value pairs and return a new Map removeKeys(Map map, Object… keys) Remove specified keys (mutates the original Map) excludeKeys(Map map, Object… keys) Remove specified keys and return a new Map removeKeysIgnoreCase(Map map, Object… keys) Remove keys ignoring case excludeKeysIgnoreCase(Map map, Object… keys) Remove keys ignoring case and return a new Map3. Map Key Naming Conversion
Method Description toSnakeCase(Map map) Convert all keys from camelCase to snake_case (e.g. userName → user_name) toCamelCase(Map map) Convert all keys from snake_case to camelCase (e.g. user_name → userName) toLowerCase(Map map) Convert all keys to lowercaseexample:
// Bean to snake_case Map
Map values = JooqMaps.toSnakeCaseWithNull(user);
values.remove("id");
// Add extra fields
JooqMaps.putEntries(values, "create_time", LocalDateTime.now());
// Filter null values
Map nonNull = JooqMaps.filterNulls(values);
// Remove keys
JooqMaps.removeKeys(values, "id", "create_time");
Enter fullscreen mode Exit fullscreen mode
추출 본문 · 출처: dev.to · https://dev.to/javaer/map-util-jooqmaps-50m1
답글 남기기