報錯
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 | 不支持 | 數據庫名 |
https://blog.csdn.net/ddfdjffd/article/details/90712080 ↩︎