Created
April 1, 2016 16:39
-
-
Save harawata/d29e49f2c75c5500ae0acf19b6a7d090 to your computer and use it in GitHub Desktop.
An example mybatis generator plugin that appends ${alias} to Base_Column_List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import org.mybatis.generator.api.IntrospectedTable; | |
import org.mybatis.generator.api.PluginAdapter; | |
import org.mybatis.generator.api.dom.xml.TextElement; | |
import org.mybatis.generator.api.dom.xml.XmlElement; | |
public class AddAliasToBaseColumnListPlugin extends PluginAdapter { | |
public boolean validate(List<String> arg0) { | |
return true; | |
} | |
@Override | |
public boolean sqlMapBaseColumnListElementGenerated(XmlElement element, IntrospectedTable introspectedTable) { | |
StringBuilder sb = new StringBuilder(); | |
int lastIndex = element.getElements().size() - 1; | |
String[] columns = element.getElements().get(lastIndex).getFormattedContent(0).split(", "); | |
for (String column : columns) { | |
if (sb.length() > 0) { | |
sb.append(", "); | |
} | |
sb.append("${alias}").append(column); | |
} | |
element.getElements().set(lastIndex, new TextElement(sb.toString())); | |
return true; | |
} | |
} |
ilkomiliev
commented
Apr 5, 2016
that's what I've ended with - second element Base_Column_List_Aliased - improvements highly appreciated, because it is my first plugin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment