tk.mybatis整合mybatis generator自動生成數據表,表名多了一個點

報錯

MySQL 中 使用 tk.mybatis 自動生成數據表,運行報錯,發現表對象的@Table名字多了個點

org.springframework.jdbc.BadSqlGrammarException:
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 ‘.job’ at line 1
The error may exist in com/tonited/hello/spring/mapper/JobMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,description FROM staff_management…job
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 ‘.job’ at line 1; bad SQL grammar []; nested exception is 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 ‘.job’ at line 1

手動解決

問題在於SQL語句中出現了兩個點

SELECT id,description  FROM staff_management..job

我們去Job這個自動生成的類中查看,發現
在這裏插入圖片描述其實把這一部分去掉就可以正常運行,手動一個一個刪掉很麻煩,也可以通過配置解決

配置解決

如果想配置生成時就去掉可以在配置文件的table標籤下添加紅框部分屬性
在這裏插入圖片描述

原理

SQL中下Catalog和Schema都屬於抽象概念,解決命名衝突
一個數據庫系統包含多個Catalog,每個Catalog包含多個Schema,每個Schema包含多個數據庫對象(表、視圖、字段等)
數據庫對象表的全限定名可表示爲:Catalog.Schema.表名
但是mysql不支持catalog

各大數據庫支持情況1

供應商 Catalog支持 Schema支持
Oracle 不支持 Oracle User ID
MySQL 不支持 數據庫名
MS SQL Server 數據庫名 對象屬主名,2005版開始有變
DB2 指定數據庫對象時,Catalog部分省略 Catalog屬主名
Sybase 數據庫名 數據庫屬主名
Informix 不支持 不需要
PointBase 不支持 數據庫名

  1. https://blog.csdn.net/ddfdjffd/article/details/90712080 ↩︎

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章