• idea中mybatis generator自动生成代码配置 数据库是sqlserver


    好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图

    具体generatorConfig.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-generator-config_1_0.dtd">
    <generatorConfiguration>
        <properties resource="jdbc.properties"></properties>
        <classPathEntry location="${dbconfig.sqlServer.driverLocation}" />
       
        <context id="context1" targetRuntime="MyBatis3">
    
            <!--<commentGenerator>
                <!– 去除自动生成的注释 –>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>-->
            <!-- 是否生成注释 去除自动生成的注释-->
            <commentGenerator>
                <property name="suppressDate" value="true"/>
    
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
            <!-- 数据库连接配置 -->
            <jdbcConnection driverClass="${dbconfig.sqlServer.driverClasss}"
                            connectionURL="${dbconfig.sqlServer.ssmDemo.read.jdbcUrl}"
                            userId="${dbconfig.sqlServer.username}"
                            password="${dbconfig.sqlServer.password}" />
           
            <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
    
            <!--配置生成的实体包
                targetPackage:生成的实体包位置,默认存放在src目录下
                targetProject:目标工程名
             -->
            <javaModelGenerator targetPackage="com.pojo"
                                targetProject="src/main/java" />
    
            <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
            <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources" />
            <!--生成Dao类存放位置-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.dao" targetProject="src/main/java">
               <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
                     <!--生成对应表及类名-->
            <!-- 配置表
                schema:不用填写
                tableName: 表名
                enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
                去除自动生成的例子
            -->
            <table schema="" tableName="UzaiSupplierStore" domainObjectName="UzaiSupplierStore" enableCountByExample="false" enableSelectByExample="false"
                   enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
            </table>
            <table schema="" tableName="UzaiCountry" enableCountByExample="false" enableSelectByExample="false"
                   enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
            </table>
    
        </context>
    </generatorConfiguration>
    

     jdbc.properties内容如下

    dbconfig.sqlServer.driverClasss=com.microsoft.sqlserver.jdbc.SQLServerDriver
    dbconfig.sqlServer.ssmDemo.read.jdbcUrl=jdbc:sqlserver://127.0.0.1;DatabaseName=Travel
    dbconfig.sqlServer.username=uzai_trip
    dbconfig.sqlServer.password=Flzx3qC!$
    #定义初始连接数
    dbconfig.initialSize=0
    #定义最大连接数
    dbconfig.maxActive=20
    #定义最大空闲
    dbconfig.maxIdle=20
    #定义最小空闲
    dbconfig.minIdle=1
    #定义最长等待时间
    dbconfig.maxWait=60000
    dbconfig.sqlServer.driverLocation=D://java//jar_package//sqljdbc4-4.0.jar
    D://java//jar_package//sqljdbc4-4.0.jar这个地址一定是在本地下载好这个jar包的地址

    jdbc.properties的参数是对应generatorConfig.xml里面的,如下图

     

    然后就是需要配置pom.xml

    以上配置完成以后,点run弹出如下界面  

    mybatis-generator:generate -e

    以上都配置以后点击运行就可以生成了

    目前发的生成的dao文件名字是Mapper,还有就是生成的数据库类没有中文注释,大多数解决方案是mysql数据库。关于sqlserver还在进一步了解中

  • 相关阅读:
    CentOS6.4 配置mysql服务器启动多个端口,同步单表数据
    生成CSV文件后再将CSV文件导入到mysql
    Quartz Cron 表达式
    Jquery 提示插件alertify 【备用】
    tnsping 命令解析
    Gearman安装及使用
    Redis安装部署
    Linux多网卡负载均衡 : bond
    ulimit命令
    Nginx 负载均衡
  • 原文地址:https://www.cnblogs.com/ok123/p/7454021.html
Copyright © 2020-2023  润新知