zoukankan      html  css  js  c++  java
  • 【mybatis】 mybatis配置详解

    持续更新中......

    中文官网文档

    ========================================

    1.mapUnderscoreToCamelCase

    是否开启驼峰命名自动映射,即从经典数据库列名 A_COLUMN 映射到经典 Java 属性名 aColumn。
    默认  false  未开启

    可能产生的问题:

    使用mybatis,  mapper.xml中这么查询,使用resultType做结果接收

     <select id="selectSimpleInfo" parameterType="com.XXX.YYY.dao.query.SimpleQuery"
                resultType="com.XXX.YYY.dao.domain.SimpleInfoDO">
            select
                sbi.p_id,
                sbi.p_status,
                sbi.p_name
            from
                simple_base_info sbi
            
    </select>

    mapper.java如下:

    List<SimpleInfoDO> selectSimpleInfo(SimpleQuery simpleQuery);

    结果类如下:

    @Getter
    @Setter
    public class SimpleInfoDO implements Serializable {
    
        private static final long serialVersionUID = 8085984502888334680L;
    
        private Long pId;
    
        private String pName;
    
        private Integer pStatus;
    
    }

    但是查询返回结果如下:

     

    问题根源:

    如果这里采用resultMap,做出参映射,是手动会把mysql对应列 和 DO对应属性 映射起来,但是这里采用resultType ,如果没有开启下划线转驼峰的配置,就会导致映射失败。

    因此需要mybatis配置开启该配置:

    mybatis:
      mapper-locations: "classpath*:mapper/*.xml"
      configuration:
        use-generated-keys: true
        map-underscore-to-camel-case: true

    2.

  • 相关阅读:
    模拟电梯运行
    用户需求调研报告
    NABC需求分析
    大道至简---读书随笔3
    二维环形数组求最大子数组和
    结对开发之求最大数组溢出问题
    结对开发之环形数组
    结对开发之电梯调度
    我看“微软拼音”
    团队开发项目之典型用户和用户场景
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/14684548.html
Copyright © 2011-2022 走看看