Mybatis+SpringBoot 项目All elements are null问题

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

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

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

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

    ……
}

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

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

    ……
}

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

# Mybatis配置
mybatis:
  mapperLocations: classpath:mapper/**/*.xml
  configuration:
    mapUnderscoreToCamelCase: true  # 驼峰转换
发布了1105 篇原创文章 · 获赞 337 · 访问量 338万+

猜你喜欢

转载自blog.csdn.net/leftfist/article/details/103846958