关键词搜索

源码搜索 ×
×

Mybatis+SpringBoot 项目All elements are null问题

发布2020-01-05浏览6088次

详情内容

问题描述:
SQL语句可以查到数据,接收对象是一个实体集合,集合元素的数量与记录数相符,但元素全部为空!提示:
All elements are null

原因:
是字段名与实体属性不够和谐导致。

数据库字段为了易读易理解,名字中间加了下划线,如v_text,v_code,那么实体也以此命名:

public class SsjcVal {
    //v_text, v_code
    private String v_text;
    private String v_code;

    ……
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

后来改成以下所示,驼峰命名,问题解决

public class SsjcVal {
    //v_text, v_code
    private String vText;
    private String vCode;

    ……
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

可能是由于我们在配置文件application.yml里指定了命名规则:

# Mybatis配置
mybatis:
  mapperLocations: classpath:mapper/**/*.xml
  configuration:
    mapUnderscoreToCamelCase: true  # 驼峰转换
  • 1
  • 2
  • 3
  • 4
  • 5

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载