MySQL 中 使用 tk.mybatis 自动生成数据表,多出了前缀

使用 tk.mybatis 自动生成实体类与 mapper ,可能会报以下异常

### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.tb_user' at line 1
### The error may exist in cn/duniqb/myshop/commons/mapper/TbUserMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,username,password,phone,email,created,updated  FROM myshop..tb_user
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.tb_user' at line 1
	......

可以看到出现了意外的语句

SELECT id,username,password,phone,email,created,updated  FROM myshop..tb_user

经查是由于在领域模型:实体类
1. 没有实现序列号接口
2. 删掉多余的点

具体参考:
自动生成的

@Table(name = "myshop..tb_content")
public class TbContent {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 内容类目ID
     */
    @Column(name = "category_id")
    private Long categoryId;
......

改正后的

@Table(name = "tb_content")
public class TbContent implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 内容类目ID
     */
    @Column(name = "category_id")
    private Long categoryId;
......

原理分析:
在SQL环境下Catalog和Schema都属于抽象概念,主要用来解决命名冲突问题
一个数据库系统包含多个Catalog,每个Catalog包含多个Schema,每个Schema包含多个数据库对象(表、视图、字段等)
如数据库对象表的全限定名可表示为:Catalog名.Schema名.表名

供应商Catalog支持Schema支持
Oracle 不支持 Oracle User ID
MySQL 不支持 数据库名
MS SQL Server 数据库名 对象属主名,2005版开始有变
DB2 指定数据库对象时,Catalog部分省略 Catalog属主名
Sybase 数据库名 数据库属主名
Informix 不支持 不需要
PointBase 不支持 数据库名

由于 MySQL 不支持 Catalog 所致,不识别前缀

没有修不好的电脑
原文地址:https://www.cnblogs.com/duniqb/p/12702459.html