這篇文章帶給大家的內容是關於mybatis反向工程的介紹(程式碼範例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
先建立一個test類別:
在main方法裡寫上如下程式碼:
Listwarnings = new ArrayList (); boolean overwrite = true; File configFile = new File("generator.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback,warnings); myBatisGenerator.generate(null);
在工程目錄下新建一個generator.xml檔案:
最後的table標籤是自己資料庫中表格的名字;資料庫的連接資訊需要自己修改
執行test類別就會自動產生自己以上設定table標籤中數據中表的對應的實體類,dao層介面以及對應的mapper映射
此外需要的jar包請自行下載:https:// github.com/Pei-Qi/mybatis_jar
以上是mybatis反向工程的介紹(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!