mybatis生成sql能否自动加上schema

公司dba要求所以sql都必须加上schema, 目前我们用的是mybatis。sql都直接写在xml里的,没有加schema.
有没有方法使mybatis生成sql时自动加上schema呢,不然代码改动工作量挺大的。谢谢了
已邀请:

guooo

赞同来自: luke

效果图
TIM截图20170828134353.png


操作步骤:
->git clone https://github.com/backkoms/my ... s.git,编译打包,install到本地或delopy私服库中均可。

1、pom.xml配置Java代码 <build>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>2.3.1</version>  
                <configuration>  
                    <source>1.7</source>  
                    <target>1.7</target>  
                    <encoding>utf8</encoding>  
                </configuration>  
            </plugin>  
            <plugin>  
                <groupId>org.mybatis.generator</groupId>  
                <artifactId>mybatis-generator-maven-plugin</artifactId>  
                <version>1.3.2</version>  
                <configuration>  
                    <configurationFile>  
                        ${basedir}/src/test/resources/conf/generatorConfig.xml  
                    </configurationFile>  
                    <overwrite>true</overwrite>  
                </configuration>  
                <dependencies>  
                    <dependency>  
                        <groupId>com.zhishi.mybatis</groupId>  
                        <artifactId>mybatis-generator-core</artifactId>  
                        <version>1.0.1</version>  
                    </dependency>  
                </dependencies>  
            </plugin>  
        </plugins>  
    </build>  

 2、generatorConfig.xml修改Xml代码 <?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
        "http://mybatis.org/dtd/mybatis ... ot%3B >  
<generatorConfiguration>  
  
    <!-- jdbc路径 -->  
    <classPathEntry  
        location="C:\dev\Reporsitory\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" />  
    <context id="context" targetRuntime="MyBatis3">  
        <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">  
            <property name="searchString" value="Example$" />  
            <property name="replaceString" value="Criteria" />  
        </plugin>  
        <plugin type="org.mybatis.generator.plugins.CachePlugin">  
            <property name="cache_eviction" value="LRU" />  
            <property name="cache_flushInterval" value="60000" />  
            <property name="cache_readOnly" value="true" />  
            <property name="cache_size" value="1560" />  
        </plugin>  
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>  
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin">  
            <property name="suppressJavaInterface" value="false" />  
        </plugin>  
        <span style="color: #333333; font-family: Arial; line-height: 26px;"><commentGenerator  
            type="org.mybatis.generator.internal.CustomeCommentGenerator"><!-- 数据库表注释生成-- >  
            <property name="javaFileEncoding" value="UTF-8" />  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="false" />  
            <property name="suppressDate" value="false" />  
        </commentGenerator></span>  
  
        <!-- 请填写connectionURL、userId、password -->  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
            connectionURL="jdbc:mysql://192.168.1.102:3306/loan" userId="root"  
            password="root" />  
  
        <!-- 生成持久化对象 -->  
        <javaModelGenerator targetPackage="com.zhishi.domain"  
            targetProject="src/test/java">  
            <property name="enableSubPackages" value="true" />  
            <property name="trimStrings" value="true" />  
        </javaModelGenerator>  
  
        <!-- 生成mapper.xml文件 -->  
        <sqlMapGenerator targetPackage="mapper/mybatis"  
            targetProject="src/test/resources">  
            <property name="enableSubPackages" value="true" />  
        </sqlMapGenerator>  
  
        <!-- 生成Mapper接口 -->  
        <javaClientGenerator targetPackage="com.zhishi.dal.mapper.credit"  
            targetProject="src/main/java" type="XMLMAPPER">  
  
            <property name="enableSubPackages" value="true" />  
        </javaClientGenerator>  
  
  
        <!-- 需要生成的数据库表 -->  
        <table tableName="tb_trx_bank" domainObjectName="TrxBank">  
            <span style="color: #333333; font-family: Arial; line-height: 26px;"><generatedKey column="tid" sqlStatement=" select replace(uuid(),'-','')" /></span><span style="color: #333333; font-family: Arial; line-height: 26px;"><!-- 主键为uuid的情况,自动生成-- ></span>  
        </table>  
    </context>  
</generatorConfiguration>  

 2、eclipse中Run as --> maven build .... -->Goals中输入命令行:mybatis-generator:generate -e 

 3、查看生成的文件Java代码 /** 
     * 主键 
     * 表 : tb_trx_bank 
     * 对应字段 : tid 
     */  
    private String tid;  
  
    /** 
     * 交易类型 
     * 表 : tb_trx_bank 
     * 对应字段 : type 
     */  
    private String type;  

string2020

赞同来自:

mybatis生成sql?mybatis都是自己写sql的
你说的是Hibernate生成sql吧

幻影灬君主 - 90后IT男

赞同来自:

貌似要手动加, Mybatis Generator 没法自动加 schema

hackpro

赞同来自:

可以支持的,mybatis-generator-core就支持的 <table catalog=""...
生成後SQL如下:
select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from trade_dev_dev.trade_bus_info
...

要回复问题请先登录注册