关于MyBatisGenerator出现的一个问题
首先,MBG是可以用视图逆向生成基本CRUD文件的
因为在MBG里,视图和表是等价的,至少在生成的时候是,但是今天却一直无法生成视图对应的POJO和MAPPER,最开始以为是不能用视图,后来查询一番,并且之前自己确实使用视图生成过,所以怎么怀疑了,之后查看了别人的博客,以为是自己的表名或者数据库名字写错了,结果也都不是。
如下图:
一直提示我:
Table conf iguration with catalog null, schema null,and table f inance .admin_ perms view did not resolve to any tables
最后还是在StackOverflow,看他们发出来的XML,发现他们的<table>
标签多一个属性,所以尝试加了一下。
最开始的配置是:
<table tableName="admin_perms_view" domainObjectName="AdminPermsView">
<property name="useActualColumnNames" value="true"/>
</table>
<table tableName="user_perms_view" domainObjectName="UserPermsView">
<property name="useActualColumnNames" value="true"/>
</table>
之后在<table>
标签上加了一下schema属性,便可以成功了。
<table schema="finance" tableName="admin_perms_view" domainObjectName="AdminPermsView">
<property name="useActualColumnNames" value="true"/>
</table>
<table schema="finance" tableName="user_perms_view" domainObjectName="UserPermsView">
<property name="useActualColumnNames" value="true"/>
</table>
不过具体原因还是不知道为什么,并且之前生成视图的时候,没有加也一样可以用。
运行成功