idea中mybatis generator自動生成程式碼配置 資料庫是sqlserver
阿新 • • 發佈:2019-02-07
好長時間沒有寫部落格了,最近公司要用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 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還在進一步瞭解中