{
XmlElement parentElement = document.getRootElement();
// 生成selectByMap的sql映射
XmlElement answer = new XmlElement("select"); //$NON-NLS-1$
answer.addAttribute(new Attribute("id", "selectByMap")); //$NON-NLS-1$
answer.addAttribute(new Attribute(
"resultMap", introspectedTable.getBaseResultMapId())); //$NON-NLS-1$
answer.addAttribute(new Attribute("parameterType", "Map")); //$NON-NLS-1$
context.getCommentGenerator().addComment(answer);
StringBuilder sb = new StringBuilder();
sb.append("select * from "); //$NON-NLS-1$
sb.append(introspectedTable
.getAliasedFullyQualifiedTableNameAtRuntime());
answer.addElement(new TextElement(sb.toString()));
XmlElement whereElement = new XmlElement("where"); //$NON-NLS-1$
for (IntrospectedColumn introspectedColumn : introspectedTable
.getAllColumns())
{
XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
sb.setLength(0);
sb.append(introspectedColumn.getJavaProperty()); //$NON-NLS-1$
sb.append(" != null"); //$NON-NLS-1$
isNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$
sb.setLength(0);
sb.append("and ");
sb.append(MyBatis3FormattingUtilities
.getAliasedEscapedColumnName(introspectedColumn));
sb.append(" = "); //$NON-NLS-1$
sb.append(MyBatis3FormattingUtilities.getParameterClause(
introspectedColumn, "")); //$NON-NLS-1$
isNotNullElement.addElement(new TextElement(sb.toString()));
whereElement.addElement(isNotNullElement);
}
answer.addElement(whereElement);
parentElement.addElement(answer);
// 生成selectCountByCriteria的sql映射
parentElement = document.getRootElement();
String fqjt = introspectedTable.getExampleType();
answer = new XmlElement("select"); //$NON-NLS-1$
answer
.addAttribute(new Attribute(
"id", "selectCount" + introspectedTable.getSelectByExampleStatementId().substring(6))); //$NON-NLS-1$
answer.addAttribute(new Attribute("resultType", "long")); //$NON-NLS-1$
answer.addAttribute(new Attribute("parameterType", fqjt)); //$NON-NLS-1$
context.getCommentGenerator().addComment(answer);
answer.addElement(new TextElement("select count(1) ")); //$NON-NLS-1$
sb = new StringBuilder();