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属性

  • 相关阅读:
    Python import模块
    Python 内置函数
    Python Pickle序列化
    android xml布局文件属性说明
    android 中动画
    Android样式——Styles
    代码家
    Android UI目录
    Android 基本控件
    android and webview 网页应用
  • 原文地址:https://www.cnblogs.com/xingrui/p/14279817.html
Copyright © 2011-2022 走看看