• mybatisplus 表名添加前缀的实现方法


    mybatis-plus 表名添加前缀的实现方法

    1、使用mybatis-plus自身的查询构造去,只需要在全局配置中添加如下配置

    mybatis-plus:
     mapper-locations: classpath:mappers/*Mapper.xml  # mapper映射文件
     global-config:
      db-config:
       table-prefix: tr_
    

    2、自定义sql语句中添加表名前缀

    在yml文件中添加如下配置

    mybatis-plus:
     mapper-locations: classpath:mappers/*Mapper.xml  # mapper映射文件
     global-config:
      db-config:
       table-prefix: tr_
     configuration-properties: 
      prefix: tr_ # 自定义sql中表名带前缀
    

    然后在自定义sql语句如下

    select * from ${prefix}user 
    

    编译后的sql语句

    select * from tr_user
    

    MybatisPlus 数据库字段使用驼峰命名法时碰到的问题

    假如有个实体类:

    class User{
     int userId;
    }
    

    按照规范,数据库User表里边对应userId的字段名应该为 user_id。

    如果数据库的字段名也是userId的话(没有下划线),那么使用MybatisPlus的时候就会碰到映射问题,实际查询的时候默认是查询user_id。

    解决办法

    .properties添加一行配置,关闭驼峰到下划线的映射即可

    mybatis-plus.configuration.map-underscore-to-camel-case=false
    

    mybaits-plus功能还是很强大的,官网地址:https://mp.baomidou.com/guide/

    到此这篇关于mybatis-plus 表名添加前缀的实现方法的文章就介绍到这了,更多相关mybatis-plus 表名添加前缀内容请搜索云海天教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持云海天教程!

    原文链接:https://blog.csdn.net/weixin_36931308/article/details/106120879


  • 相关阅读:
    使用url_for()时,会自动调用转换器的to_url()方法
    自定义flask转换器
    flask自有转换器:int、float、path。默认string
    flask中重定向所涉及的反推:由视图函数反推url
    mysqldump 命令使用
    PIX 防火墙
    MySQL 常用show 语句
    防火墙与入侵检测技术
    mysql DQL语言操作
    mysql 视图
  • 原文地址:https://www.cnblogs.com/javalinux/p/14338780.html
Copyright © 2020-2023  润新知