zoukankan      html  css  js  c++  java
  • mybaties返回值对对象,字段名与属性名不匹配问题

    字段名与属性名不一致,会造成属性值为null

    1、默认行为根据名称相同自动匹配
    When auto-mapping results MyBatis will get the column name and look for a** property** with the same name ignoring case.
    2、一般开启驼峰命名
    Usually database columns are named using uppercase letters and underscores between words and java properties often follow the camelcase naming covention. To enable the auto-mapping between them set the setting mapUnderscoreToCamelCase to true.

    例如
    class User{
    private String userName;
    getset方法;
    }
    user表中字段名为:user_name
    解决思路:
    1、select user_name AS userName,起别名。
    优点:最简单,易理解
    缺点:如果有N个查询,每个查询写一遍别名,需要N遍,有耐心你就写,等到字段名有修改,你在一处一处去修改,加班开始哈哈哈。
    2、添加类属性名与数据库字段名映射关系。(column为表中字段名)



    优点:映射关系可以复用
    缺点:不能一眼看出对应的实体类,需要先看resultMap,在找到其type属性

  • 相关阅读:
    Storybook 最新教程
    Monorepo All In One
    zsh & git alias
    vue-cli emit webpack config
    iflab隔壁ios组新生面试题
    [转]sprintf
    python版归并排序
    关于linux下GCC生成共享库(动态链接库)的探究
    ubuntu不小心删除了libc-bin的恢复办法
    python实现栈
  • 原文地址:https://www.cnblogs.com/xingrui/p/14279817.html
Copyright © 2011-2022 走看看