Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字段名字能否做到驼峰和下划线的映射 #9

Open
KennyNote opened this issue Feb 24, 2022 · 5 comments
Open

字段名字能否做到驼峰和下划线的映射 #9

KennyNote opened this issue Feb 24, 2022 · 5 comments

Comments

@KennyNote
Copy link

前端传入的vo都是下划线规则的属性,但是dto是驼峰规则的属性,现在转起来麻烦些,可否做到自动识别。

@fuzhengwei
Copy link
Owner

可以提供一些案例参考吗,避免开发后有些兼容问题

@KennyNote
Copy link
Author

可以提供一些案例参考吗,避免开发后有些兼容问题

场景基本如下:
1.前端传入的参数(json样例):{
"min_limit_age": 0,
"max_limit_age": 0,
"show_total_limits": 0,
"session_total_limits": 0,
},此时后端@RequestBody 修饰的类xxxDTO也是按照下划线格式接收前端传入的json的,但是数据库映射的PO是驼峰的。

@fuzhengwei
Copy link
Owner

  1. min_limit_age => minLimitAge 这样的吗?
  2. 从 xxxDTO(含下划线) 转化到 PO(驼峰) 这样是吧

@KennyNote
Copy link
Author

  1. min_limit_age => minLimitAge 这样的吗?
  2. 从 xxxDTO(含下划线) 转化到 PO(驼峰) 这样是吧

yes!!!

@senowang
Copy link

senowang commented Jul 4, 2024

这种不应该是通过配置jackson 来解决问题吗?

String json = "{\"user_name\":\"wang\"}";
 ObjectMapper objectMapper = new ObjectMapper();
 objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SnakeCaseStrategy.INSTANCE);
  U u = objectMapper.readValue(json, U.class);
  System.out.println(u.getUserName());
 public static class U{
        private String userName;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants