The connected database is SQL server2008, so the required file is sqljdbc4.jar
The lib libraries used are:
Create a new src folder in the lib library directory to store the generated files, and then create a new generatorConfig.xml
The code inside is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration .//EN" "http://mybatis.org/dtd/mybatis-generator-config__.dtd"> <generatorConfiguration> <!-- Database Driver--> <!-- sqljdbc4.jar is a SQLServer database connection jar package. If you want to connect to the MySQL database, directly change sqljdbc4.jar to mysql-connector-java-5.1.25-bin.jar --> <classPathEntry location="sqljdbc.jar"/> <context id="DBTables" targetRuntime="MyBatis"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- Whether to remove the automatically generated comments true: Yes: false: No--> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--Database link URL, username, password--> <!--Connect Data SQLServer --> <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://127.0.0.1:1433;databaseName=dbSSMTEST" userId="sa" password="123"> <!--Connecting database MySQL --> <!-- <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://...:/ypzlmanagement" userId="root" password="hewei"> --> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- Generate the package name and location of the model --> <!-- targetPackage="com.ssm.pojo" is the storage path for the generated code. Here is the storage path according to your path --> <javaModelGenerator targetPackage="com.ssm.pojo" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- Generate the package name and location of the mapping file --> <!-- targetPackage="com.ssm.pojo" is the storage path for the generated code. Here is the storage path. --> <sqlMapGenerator targetPackage="com.ssm.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- The package name and location of the generated DAO --> <!-- targetPackage="com.ssm.pojo" is the storage path for the generated code. Here is the storage path. Here is the storage path. <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- The table to be generated is the table name in the database or the view name domainObjectName is the entity class name--> <!-- The table name is the table name of the database mapping file domainObjectName The entity class name to be generated is modified according to your needs--> <table tableName="student" domainObjectName="student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
Finally, find the root directory of lib under the cmd console and execute the following statement
Java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite
As shown in the figure:
Then you can see the automatically generated files in the folder directory
The above is a detailed explanation introduced by the editor to you. MyBatis Generator automatically creates code (dao, mapping, poji). I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!