feat(config): 启用驼峰命名到下划线映射并完善用户实体配置

- 将 application-local.yml 和 application-pre.yml 中 mybatis-plus 的 map-underscore-to-camel-case 设置为 true
- 在 StringUtil 类中新增 camelToSnakeCase 方法用于驼峰转下划线命名
- 更新 camelToKebabCase 方法注释并修正转换逻辑
- 为 User 实体类添加 @TableId 注解配置自增主键
This commit is contained in:
海言
2026-05-28 15:41:24 +08:00
parent 6e5a3a3142
commit 9554192e85
4 changed files with 25 additions and 4 deletions

View File

@@ -10,10 +10,10 @@ package cn.xf.basedemo.common.utils;
public class StringUtil {
/**
* 驼峰命名法转下划线命名法
* 驼峰命名法转短横线命名法kebab-case
*
* @param camelCase 驼峰命名法字符串
* @return 下划线命名法字符串
* @return 短横线命名法字符串
*/
public static String camelToKebabCase(String camelCase) {
if (camelCase == null || camelCase.isEmpty()) {
@@ -26,4 +26,22 @@ public class StringUtil {
// 转换为小写
return result.toLowerCase();
}
/**
* 驼峰命名法转下划线命名法snake_case
*
* @param camelCase 驼峰命名法字符串
* @return 下划线命名法字符串
*/
public static String camelToSnakeCase(String camelCase) {
if (camelCase == null || camelCase.isEmpty()) {
return camelCase;
}
// 使用正则表达式将大写字母前插入一个"_"
String result = camelCase.replaceAll("([a-z])([A-Z])", "$1_$2");
// 转换为小写
return result.toLowerCase();
}
}

View File

@@ -1,5 +1,7 @@
package cn.xf.basedemo.model.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@@ -17,6 +19,7 @@ import java.util.Date;
@TableName(value = "xf_user")
public class User {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;

View File

@@ -66,7 +66,7 @@ springdoc:
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
map-underscore-to-camel-case: true
auto-mapping-behavior: full
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启SQL语句打印
mapper-locations: classpath*:mapper/**/*Mapper.xml

View File

@@ -68,7 +68,7 @@ springdoc:
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
map-underscore-to-camel-case: true
auto-mapping-behavior: full
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启SQL语句打印
mapper-locations: classpath*:mapper/**/*Mapper.xml