I didn't know that ibatis also has an automatic code generation tool similar to hibernate. Today I found abator, which is quite good. I tried it on ecelipse:
1. Get abator
Http://ibatis.apache.org/abator.html
Eclipse can automatically update to obtain this plug-in. For details, refer to the official installation steps.
2. After the installation is complete, a new file type abator for ibatis configuration file is displayed in the new menu. This is the configuration file of abator. For details about the configuration file, see composer:
XML Code
- <Abatorconfiguration>
- <Abatorcontext> <! -- Todo: Add database connection information -->
- <! -- Here we should all understand what it means -->
- <Jdbcconnection driverclass = "com. MySQL. JDBC. Driver"
- Connectionurl = "JDBC: mysql: // localhost: 3306/lunjian"
- Userid = "root"
- Password = "admin">
- <! -- MySQL driver jar -->
- <Classpathentry location = "D:/tomcat5/webapps/moloonmarket/WEB-INF/lib/mysql-connector-java-5.0.4-bin.jar"/>
- </Jdbcconnection>
- <! -- Targetpackage specifies a package name to store model bean. targetproject is the project name -->
- <Javamodelgenerator targetpackage = "com. itatis. Domain" targetproject = "mjtserver"/>
- <! -- Sqlmapgenerator specifies a package name to store sqlmap. xml -->
- <Sqlmapgenerator targetpackage = "com. itatis. Persistence. xml" targetproject = "mjtserver"/>
- <! -- Daogenerator specifies a package name to store Dao and daoimpl -->
- <Daogenerator type = "ibatis" targetpackage = "com. itatis. Persistence. sqlmapdao" targetproject = "mjtserver"/>
- <! -- Table name, which can be multiple. By default, all fields are generated if columnoverride is not written. -->
- <Table tablename = "users">
- <! -- <Columnoverride column = "??? "Property = "??? "/> -->
- </Table>
- </Abatorcontext>
- </Abatorconfiguration>
<Abatorconfiguration> <abatorcontext> <! -- Todo: Add database connection information --> <! -- Here we should all understand what it means --> <jdbcconnection driverclass = "com. mySQL. JDBC. driver "connectionurl =" JDBC: mysql: // localhost: 3306/lunjian "userid =" root "Password =" admin "> <! -- MySQL driver jar --> <classpathentry location = "D:/tomcat5/webapps/moloonmarket/WEB-INF/lib/mysql-connector-java-5.0.4-bin.jar"/> </jdbcconnection> <! -- Targetpackage specifies a package name to store model bean. targetproject is the project name --> <javamodelgenerator targetpackage = "com. itatis. Domain" targetproject = "mjtserver"/> <! -- Sqlmapgenerator: specify a package name to store sqlmap. xml --> <sqlmapgenerator targetpackage = "com. itatis. Persistence. xml" targetproject = "mjtserver"/> <! -- Daogenerator specifies a package name to store Dao and daoimpl --> <daogenerator type = "ibatis" targetpackage = "com. itatis. Persistence. sqlmapdao" targetproject = "mjtserver"/> <! -- Table name, which can be multiple. By default, all fields are generated without writing columnoverride --> <Table tablename = "users"> <! -- <Columnoverride column = "??? "Property = "??? "/> --> </Table> </abatorcontext> </abatorconfiguration>
3. Right-click the configuration file and click Generate ibatis artifacts to generate the file.
In this way, the basic file is generated,
Including: users. Java, usersexample. Java, usersdao. Java, usersdaoimpl. Java, users_sqlmap.xml
Note that a usersexample is generated here. java, inherited from users. java, I personally think it is useless. Dao also contains many common interfaces. The implementation in daoimpl is completely based on ibatis, but it is relatively large, you need to delete some useless things in use sqlmap. the XML file is also large, and the head is dizzy without patience, but the SQL statements in it are still relatively standard. If you use it yourself and want the process to be clear, it takes some time to change.
You have time to check how the abator code is written. It is best to modify the code. It is suitable for simple development.