Automatic generation of DAO, Model, mapping related files using Mybatis-generator

Source: Internet
Author: User
Tags manual writing

Recently, I have been learning the SSM framework, and today we have a question about mybatis generation and record it.

http://blog.csdn.net/zhshulin/article/details/37956105, I tested it on this blog.

First introduce MyBatis belongs to semi-automatic ORM, in the use of this framework, the greatest amount of work is to write mapping mapping files, because manual writing is easy to make mistakes, we can use Mybatis-generator to help us automatically generate files.

1. Related documents:

2.generatorconfig.xml File Configuration

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "/http Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorConfiguration> <!--database-driven < Classpathentry location= "Mysql-connector-java-5.1.25-bin.jar"/><context id= "DB2Tables" TargetRuntime= " MyBatis3 "> <commentGenerator> <property name=" Suppressdate "value=" true "/> <!--whether to go In addition to automatically generated annotationstrueIsfalse: No---<property name= "suppressallcomments" value= "true"/> </commentGenerator> &l t;! --Database link URL, user name, password---<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql://127.0             .0.1/myspring "userid=" root "password=" root "> </jdbcConnection> <javaTypeResolver> <property name= "Forcebigdecimals" value= "false"/> </javaTypeResolver> <javamodelgene Rator targetpackage= "Test.model" targetproject= "src" > <property name= "enablesubpackages" value= "true"/&G             T <property name= "Trimstrings" value= "true"/> </javaModelGenerator> <sqlmapgenerator t        Argetpackage= "test.mapping" targetproject= "src" > <property name= "enablesubpackages" value= "true"/> </sqlMapGenerator> <javaclientgenerator type= "Xmlmapper" targetpackage= "Test.dao" Targetproject = "src"> <property name= "enablesubpackages" value= "true"/> </javaClientGenerator> <!--to The resulting table tableName is the table name or view name in the database Domainobjectname is the entity class name--<table tablename= "user_t" domainobjectname= "user" Ena Blecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= " False "Selectbyexamplequeryid=" false "></table> </context> </generatorConfiguration>

Which is the reference to http://blog.csdn.net/zhshulin/article/details/23912615 this blog

3. Conduct the test

Hold down the SHIFT key in the directory and right-click the "Open command Window Here" to copy and paste the file code of the generated statement. This one is not mentioned in the blog, but bitter me, but fortunately found another blog, is the solution of the mystery. Http://www.cnblogs.com/smileberry/p/4145872.html

Entering statements on the command line

Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generatorconfig.xml-overwrite

4. If you encounter such a wrong workaround  

When the use of MyBatis generated when encountered problems, the preamble does not allow the content of the problem, if there is such a problem, need to open with notepad++ tool, choose the format to UTF-8 no BOM format encoding , then run the solution, the principle is to XML file replaced by UTF-8 format will have a BOM header Java read the time will be error

Automatic generation of DAO, Model, mapping related files using Mybatis-generator

Related Article

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.