Mybatis generator overwrites the XML file

Source: Internet
Author: User

Mybatis generator is generated by append by default. Therefore, if you want to regenerate the code, delete the original file first.

Solution:

1: create a custom patch class.

Overwritexmlplugin. Java

Package COM. my. common. generator; import Java. util. list; import Org. mybatis. generator. API. generatedxmlfile; import Org. mybatis. generator. API. introspectedtable; import Org. mybatis. generator. API. pluginadapter;/*** @ author wulm * @ date 7:39:45 on May 25 * @ version 1.0.0 */public class overwritexmlplugin extends pluginadapter {@ override public Boolean sqlmapgenerated (generatedxmlfile sqlmap, introspectedtable extends) {sqlmap. setmergeable (false); return Super. sqlmapgenerated (sqlmap, introspectedtable) ;}@ override public Boolean validate (list <string> warnings) {return true ;}}
View code

Note: The principle is to rewrite the sqlmapgenerated method. Set sqlmap. setmergeable (false );. Ismergeable is true by default, so it is set to false here.

 

2: add

<! -- Overwrite the XML file -->
<Plugin
Type = "com. My. Common. generator. myplugins. overwritexmlplugin"/>

 

When you execute the statement again, the original XML will be overwritten.

 

 

In addition, if you want to override the original Java file, it is recommended to use Java code to generate code, please refer to the official website: http://mbg.cndocs.ml/running/runningWithJava.html (use xml configuration file to run mbg from Java), the code inside the settings

Boolean overwrite = true;

 

Mybatis generator overwrites the XML file

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.