generator自動生成mybatis配置和類信息報Table configuration with catalog null錯誤解決

Mybatis generator,Table configuration with catalog null, schema null報錯解決

運行generator命令自動生成mybatis配置和類的過程中報錯。
下面列出報錯可能的原因及對應解決辦法。

原因一:mybatis-generator:generate命令寫錯了

將命令寫錯寫成了mybatis-generator:generator。一個單詞的差別。
報如下錯誤信息:
在這裏插入圖片描述

解決方法

將運行窗口中的命令拼寫正確即可。
找到generatorConfig.xml文件,右擊選擇菜單中的Run As->Run Configurations…->Maven Build->New_configuration
在這裏插入圖片描述
正確命令爲:

mybatis-generator:generator

在這裏插入圖片描述

原因二:generatorConfig.xml文件中數據庫的驅動包路徑問題

在generatorConfig.xml配置文件查看如下信息:
在這裏插入圖片描述
路徑錯誤,或驅動包版本不匹配,導致驅動包加載出錯。

解決方法

將對應版本正確的jar包路徑填入即可。
代碼如下:

 <classPathEntry location="D:\maven_repo\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" />

原因三:數據庫中沒建表

用navicat或PL/sql等可視化數據庫管理工具查看對應數據庫信息。

在這裏插入圖片描述
查看發現沒有創建需要使用的表。

解決方法

使用數據庫管理工具或sql語句在對應數據庫創建需要用的表。
數據庫建表語句:

#用戶表
create table cms_user(
  id bigint primary key auto_increment,
  username varchar(100),
  password varchar(100),
  telephone varchar(60),
  realname varchar(100),
  gender varchar(1) check(gender in('F','M')),
  birth date,
  register_time date,
  status varchar(100),
  user_face varchar(1000)

);


#日誌表
create table cms_logs(
  id bigint primary key auto_increment,
  content text,
  aution_time date,
  user_id bigint references cms_user(id)
);


#權限表
create table cms_privilege(
  id bigint primary key auto_increment,
  name varchar(100),
  description varchar(4000),
  route varchar(100),
  type varchar(20) check(gender in('menu','tab','action')),
  icon varchar(1000),
  parent_id bigint references cms_privilege(id)
);

#角色
create table cms_role(
  id bigint primary key auto_increment,	
  name varchar(100)
);


#用戶角色
create table cms_user_role(
  id bigint primary key auto_increment,	
  user_id bigint references cms_user(id),
  role_id bigint references cms_role(id)
);



#橋表cms_role_privilege
create table cms_role_privilege(
 id bigint primary key auto_increment,
 role_id  bigint references cms_role(id),
 privilege_id bigint references cms_privilege(id)
);


#欄目
create table cms_category(
 id bigint primary key auto_increment,
 name varchar(100),
 description varchar(4000),
 no bigint, 
 parent_id bigint references cms_category(id)
);


#文章
create table cms_article(
  id bigint primary key auto_increment,
  title varchar(1000),
  content text,
  source text,
  publish_time date,
  read_times date,
  status varchar(100),
  thumb_up bigint,
  thumb_down bigint,
  author_id bigint references cms_user(id),
  category_id bigint references cms_category(id)
);


#評論
create table cms_comment(
  id bigint primary key auto_increment,
  content text,
  comment_time date,
  status varchar(100),
  user_id bigint references cms_user(id),
  article_id bigint references cms_article(id),
  parent_id bigint references cms_comment(id)
);

直接使用工具建表:
在這裏插入圖片描述

原因四:generatorConfig.xml文件中沒有配置映射信息

在generatorConfig.xml文件中如下位置缺少映射配置:

在這裏插入圖片描述

解決方法

在generatorConfig.xml文件中查看有沒有:

<table tableName="" domainObjectName=""></table>

的格式配置。

有的話直接將tableName對應改寫爲自己的表名,domainObjectName改爲所要生成的實體名即可。
沒有就添加如下格式代碼:

    <table tableName="cms_category" domainObjectName="Category" ></table>
    <table tableName="cms_article" domainObjectName="Article" ></table>
    <table tableName="cms_logs" domainObjectName="Logs" ></table>
    <table tableName="cms_privilege" domainObjectName="Privilege" ></table>
    <table tableName="cms_role" domainObjectName="Role" ></table>
    <table tableName="cms_role_privilege" domainObjectName="RolePrivilege" ></table>
    <table tableName="cms_user" domainObjectName="User" ></table>
    <table tableName="cms_comment" domainObjectName="Comment" ></table>
    <table tableName="cms_user_role" domainObjectName="UserRole" ></table>

解決結果

將如上所有問題排查,項目成功運行。
在這裏插入圖片描述

總結

這次錯誤信息耽誤了我一晚上加一上午,上面的情況是實際項目操作中所遇到的問題,希望以後細心一些。記錄一下自己的粗心,細節真的太重要了。排查問題的過程是很快樂的,解決問題的成就感也是沒法形容的,繼續努力!

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