Mbatis _ reverse engineering, mbatis Reverse Engineering

Source: Internet
Author: User

Mbatis _ reverse engineering, mbatis Reverse Engineering

 

 

Mybatis Reverse Engineering

What is reverse engineering?

Mybatis requires programmers to write their own SQL statements. mybatis provides reverse engineering and automatically generates the required code (mapper, java, po...) for a single table ...) this is not recommended for new users. In the future development of enterprises, java code is generated from database tables, which mainly saves programmer development time.

 

Download reverse engineering:

  

Usage: Decompress the internal docsfile, find the index.html guide, and find the running mode.

We recommend that you use java programs instead of plug-in tools.

  

 

    Create a project, package, class, and import the following things

  

   Specific category:

 

Xml configuration:

In this example, the xml configuration is the same as that in index, and each function is commented out. You can use the default configuration for other configurations.

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <! DOCTYPE generatorConfiguration 3 PUBLIC "-// mybatis.org//DTD MyBatis Generator Configuration 1.0 // EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 6 <generatorConfiguration> 7 <! -- Import the configuration file --> 8 <properties resource = "db. properties"/> 9 <! -- Specify the jdbc driver path <classPathEntry location = "E: /Learning software/Eclipse Project/generatorSqlmapCustom/lib/mysql-connector-java-5.1.40-bin.jar "/> --> 10 11 <context id =" DB2Tables "targetRuntime =" MyBatis3 "> 12 <commentGenerator> 13 <! -- Whether to remove automatically generated comments: true: false: No --> 14 <property name = "suppressAllComments" value = "true"/> 15 </commentGenerator> 16 17 <! -- Link database information: Driver Class, link database address, user name, password 18 driverClass = "$ {jdbc. driver} "19 connectionURL =" $ {jdbc. url} "20 userId =" $ {jdbc. username} "21 password =" $ {jdbc. password} "/> 22 --> 23 <jdbcConnection 25 driverClass =" org. gjt. mm. mysql. driver "26 connectionURL =" jdbc: mysql: // localhost: 3306/store "27 userId =" root "28 password =" 123456 "/> 29 <! -- <JdbcConnection 30 driverClass = "oracle. jdbc. oracleDriver "31 connectionURL =" jdbc: oracle: thin: @ 127.0.0.1: 1521: test "32 userId =" "33 password =" "> 34 </jdbcConnection> link to oracle database --> 35 36 <javaTypeResolver> 37 <! -- The default value is false. The jdbc decimal and NUMERIC types are parsed to Integer. If the value is true, the jdbc decimal and NUMERIC types are parsed to java. math. bigDecimal --> 38 <property name = "forceBigDecimals" value = "false"/> 39 </javaTypeResolver> 40 <! -- TargetProject: the first package name and the second path for generating the PO class --> 41 <javaModelGenerator targetPackage = "com. kjczwl. ssm. po "targetProject = ". /src "> 42 <! -- EnableSubPackages: whether to use schema as the package suffix --> 43 <property name = "enableSubPackages" value = "false"/> 44 <! -- Space before and after the value returned from the database --> 45 <property name = "trimStrings" value = "true"/> 46 </javaModelGenerator> 47 <! -- TargetPackage: location where the mapper ing file is generated --> 48 <sqlMapGenerator targetPackage = "com. kjczwl. ssm. mapper" targetProject = "./src"> 49 <! -- EnableSubPackages: whether to use schema as the package suffix --> 50 <property name = "enableSubPackages" value = "false"/> 51 </sqlMapGenerator> 52 <! -- TargetPackage: Location generated by the ER interface --> 53 <javaClientGenerator type = "XMLMAPPER" targetPackage = "com. kjczwl. ssm. mapper" targetProject = "./src"> 54 <! -- EnableSubPackages: whether to use schema as the package suffix --> 55 <property name = "enableSubPackages" value = "false"/> 56 </javaClientGenerator> 57 <! -- Specify the generated data table --> 58 <table tableName = "items"> </table> 59 <table tableName = "user"> </table> 60 </context> 61 </generatorConfiguration>

 

Run your project and refresh F5. The po mapper. xml and so on will appear below .....

  

Misaligned problem:

Problem 1: The specified path cannot be found.

    

    Solution: xml configuration, okay, and OK. The same can be said if it is not good. There is no error code prompt. There is no way to do this. Please read the above path carefully and you will know about this problem, finally, we can find out that there is a space, and a space can be put upside down and cannot get what we want. Therefore, we must be careful when configuring xml configuration. Otherwise, a little bit will cause a big problem.

Problem 2: The system cannot find the specified path

     

    Solution: This is simple, because all the paths in the lib should be equal:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.