利用MyBatis如何創(chuàng)建一個逆向工程?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
1.什么是逆向工程
mybaits需要程序員自己編寫sql語句,mybatis官方提供逆向工程 可以針對單表自動生成mybatis執(zhí)行所需要的代碼(mapper.java,mapper.xml、po..)
企業(yè)實際開發(fā)中,常用的逆向工程方式:
由于數(shù)據庫的表生成java代碼。
2.下載逆向工程
mybatis-generator-core-1.3.2-bundle.zip
3.使用方法(會用)
3.1運行逆向工程
官方文檔中提供的運行逆向工程的幾種方法
Running MyBatis Generator
MyBatis Generator (MBG) can be run in the following ways:
(1)From the command prompt with an XML configuration
(2)As an Ant task with an XML configuration
(3)As a Maven Plugin
(4)From another Java program with an XML configuration
(5)From another Java program with a Java based configuration
(6)還可以通過eclipse的插件生成代碼
建議使用java程序方式(From another Java program with an XML configuration),不依賴開發(fā)工具。
下面創(chuàng)建一個生成逆向文件的工程,將自動生成的文件再拷貝到原工程中去(這么做是為了放止直接在源文件中生成會覆蓋掉同名文件)
導入的jar包和工程結構截圖如下:
如圖
3.2生成代碼配置文件
generatorConfig.xml:
<?xml version="1.0" encoding="UTF-8"?>