本文整理了Java中org.mybatis.generator.api.dom.java.Method
类的一些代码示例,展示了Method
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method
类的具体详情如下:
包路径:org.mybatis.generator.api.dom.java.Method
类名称:Method
暂无
代码示例来源:origin: shuzheng/zheng
Method setLimit = new Method();
setLimit.setVisibility(JavaVisibility.PUBLIC);
setLimit.setName("setLimit");
setLimit.addParameter(new Parameter(integerWrapper, "limit"));
setLimit.addBodyLine("this.limit = limit;");
topLevelClass.addMethod(setLimit);
Method getLimit = new Method();
getLimit.setVisibility(JavaVisibility.PUBLIC);
getLimit.setReturnType(integerWrapper);
getLimit.setName("getLimit");
getLimit.addBodyLine("return limit;");
topLevelClass.addMethod(getLimit);
Method setOffset = new Method();
setOffset.setVisibility(JavaVisibility.PUBLIC);
setOffset.setName("setOffset");
setOffset.addParameter(new Parameter(integerWrapper, "offset"));
setOffset.addBodyLine("this.offset = offset;");
topLevelClass.addMethod(setOffset);
Method getOffset = new Method();
getOffset.setVisibility(JavaVisibility.PUBLIC);
getOffset.setReturnType(integerWrapper);
getOffset.setName("getOffset");
getOffset.addBodyLine("return offset;");
topLevelClass.addMethod(getOffset);
代码示例来源:origin: abel533/Mapper
/**
* setter方法注释
*
* @param method
* @param introspectedTable
* @param introspectedColumn
*/
@Override
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**");
if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
sb.append(" * 设置");
sb.append(introspectedColumn.getRemarks());
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" *");
}
Parameter parm = method.getParameters().get(0);
sb.setLength(0);
sb.append(" * @param ");
sb.append(parm.getName());
if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
sb.append(" ");
sb.append(introspectedColumn.getRemarks());
}
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" */");
}
代码示例来源:origin: cxjava/mybatis-generator-core
public final List<Method> getMethodClones(CommentGenerator commentGenerator, IntrospectedTable introspectedTable) {
configure();
List<Method> answer = new ArrayList<Method>();
for (Method oldMethod : methods) {
Method method = new Method();
for (String bodyLine : oldMethod.getBodyLines()) {
method.addBodyLine(bodyLine);
}
for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) {
method.addException(fqjt);
}
for (Parameter parm : oldMethod.getParameters()) {
method.addParameter(parm);
}
method.setConstructor(oldMethod.isConstructor());
method.setFinal(oldMethod.isFinal());
method.setStatic(oldMethod.isStatic());
method.setName(oldMethod.getName());
method.setReturnType(oldMethod.getReturnType());
method.setVisibility(oldMethod.getVisibility());
commentGenerator.addGeneralMethodComment(method, introspectedTable);
answer.add(method);
}
return answer;
}
代码示例来源:origin: org.mybatis.generator/mybatis-generator-core
@Override
protected void configureConstructorTemplate() {
Method method = new Method();
method.setConstructor(true);
method.setVisibility(JavaVisibility.PUBLIC);
method.addBodyLine("super();"); //$NON-NLS-1$
setConstructorTemplate(method);
}
代码示例来源:origin: roncoo/roncoo-mybatis-generator
public final Method getConstructorClone(CommentGenerator commentGenerator,
FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
configure();
Method answer = new Method();
answer.setConstructor(true);
answer.setName(type.getShortName());
answer.setVisibility(constructorTemplate.getVisibility());
for (Parameter parm : constructorTemplate.getParameters()) {
answer.addParameter(parm);
}
for (String bodyLine : constructorTemplate.getBodyLines()) {
answer.addBodyLine(bodyLine);
}
for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
answer.addException(fqjt);
}
commentGenerator.addGeneralMethodComment(answer, introspectedTable);
return answer;
}
代码示例来源:origin: sanluan/PublicCMS
Method m = new Method();
m.setVisibility(JavaVisibility.PUBLIC);
if (it.getName().endsWith("WithRowbounds")) {
m.setName(it.getName().replace("WithRowbounds", "WithPage"));
FullyQualifiedJavaType pageHandler = new FullyQualifiedJavaType("com.publiccms.common.handler.PageHandler");
m.setReturnType(pageHandler);
topLevelClazz.addImportedType(pageHandler);
m.addBodyLine(
"PageHandler page = new PageHandler(pageIndex, pageSize, mapper.countByExample(example), null);");
StringBuilder bodyline = new StringBuilder();
bodyline.append("page.setList(mapper.");
bodyline.append(it.getName());
bodyline.append("(");
List<Parameter> params = it.getParameters();
List<String> paramTxt = new ArrayList<>();
for (Parameter p : params) {
topLevelClazz.addImportedType(t);
if ("RowBounds".equals(t.getShortNameWithoutTypeArguments())) {
m.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "pageIndex"));
m.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "pageSize"));
paramTxt.add("new RowBounds((pageIndex - 1) * pageSize, pageSize)");
} else {
Parameter tmp = new Parameter(t, p.getName());
m.addParameter(tmp);
paramTxt.add(tmp.getName());
m.addBodyLine(bodyline.toString());
m.addBodyLine("return page;");
代码示例来源:origin: io.github.cgi/mybatis-generator-plugins
private Method generateDecoratedMapperMethod(Method method, IntrospectedTable introspectedTable) {
Method methodToGenerate = new Method(config.methodToGenerateName);
methodToGenerate.setVisibility(method.getVisibility());
methodToGenerate.setReturnType(method.getReturnType());
context.getCommentGenerator().addGeneralMethodComment(methodToGenerate, introspectedTable);
List<String> annotations = method.getAnnotations();
for (String a : annotations) {
if (a.matches("@.*Provider.*")) {
methodToGenerate.addAnnotation(a.replace(config.methodToDecorateName, config.methodToGenerateName));
} else
methodToGenerate.addAnnotation(a);
}
List<Parameter> params = method.getParameters();
for (Parameter p : params) {
methodToGenerate.addParameter(p);
}
return methodToGenerate;
}
代码示例来源:origin: io.github.cgi/mybatis-generator-plugins
private Method generateDecoratedProviderMethod(Method method, TopLevelClass topLevelClass,
IntrospectedTable introspectedTable) {
Method m = new Method(config.methodToGenerateName);
m.setVisibility(method.getVisibility());
m.setReturnType(method.getReturnType());
List<Parameter> params = method.getParameters();
for (Parameter p : params) {
m.addParameter(p);
}
StringBuilder sb =
new StringBuilder("String sql = ")
.append("this.").append(method.getName()).append("(");
for (Parameter p : params) {
sb.append(p.getName());
sb.append(",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(");");
m.addBodyLine(sb.toString());
m.addBodyLine("return \"" + config.sql + "\".replace(\"#{methodToDecorate}\", sql);");
return m;
}
代码示例来源:origin: org.mybatis.generator/mybatis-generator-core
ModelClassType modelClassType) {
Method fluentMethod = new Method();
fluentMethod.setVisibility(JavaVisibility.PUBLIC);
fluentMethod.setReturnType(topLevelClass.getType());
fluentMethod.setName("with" + method.getName().substring(3)); //$NON-NLS-1$
fluentMethod.getParameters().addAll(method.getParameters());
.append(method.getName())
.append('(')
.append(introspectedColumn.getJavaProperty())
.append(");"); //$NON-NLS-1$
fluentMethod.addBodyLine(sb.toString()); //$NON-NLS-1$
fluentMethod.addBodyLine("return this;"); //$NON-NLS-1$
代码示例来源:origin: dcendents/mybatis-generator-plugins
void addGenericMethod(Method method, FullyQualifiedJavaType returnType, FullyQualifiedJavaType... types) {
method.addAnnotation("@Override");
if (!methodsAdded.contains(method.getName())) {
Method genericMethod = new Method(method.getName());
genericMethod.addJavaDocLine("/**");
genericMethod.addJavaDocLine(" * This method was generated by MyBatis Generator.");
genericMethod.addJavaDocLine(" *");
genericMethod.addJavaDocLine(" * @mbg.generated");
genericMethod.addJavaDocLine(" */");
genericMethod.setReturnType(returnType);
for (int i = 0; i < method.getParameters().size(); i++) {
Parameter parameter = method.getParameters().get(i);
FullyQualifiedJavaType paramType = types.length > i ? types[i] : parameter.getType();
Parameter genericParameter = new Parameter(paramType, parameter.getName());
genericMethod.addParameter(genericParameter);
}
genericInterface.addMethod(genericMethod);
methodsAdded.add(method.getName());
}
}
代码示例来源:origin: roncoo/roncoo-mybatis-generator
/**
* add method
*
*/
protected void addMethod(TopLevelClass topLevelClass, String tableName) {
Method method2 = new Method();
for (int i = 0; i < methods.size(); i++) {
Method method = new Method();
method2 = methods.get(i);
method = method2;
method.removeAllBodyLines();
method.removeAnnotation();
StringBuilder sb = new StringBuilder();
sb.append("return this.");
sb.append(getDaoShort());
sb.append(method.getName());
sb.append("(");
List<Parameter> list = method.getParameters();
for (int j = 0; j < list.size(); j++) {
sb.append(list.get(j).getName());
sb.append(",");
}
sb.setLength(sb.length() - 1);
sb.append(");");
method.addBodyLine(sb.toString());
topLevelClass.addMethod(method);
}
methods.clear();
}
代码示例来源:origin: org.mybatis.generator/mybatis-generator-core
/**
* Use the method copy constructor to create a new method, then
* add the rowBounds parameter.
*
* @param fullyQualifiedTable the table
* @param method the method
*/
private void copyAndAddMethod(Method method, Interface interfaze) {
Method newMethod = new Method(method);
newMethod.setName(method.getName() + "WithRowbounds"); //$NON-NLS-1$
newMethod.addParameter(new Parameter(rowBounds, "rowBounds")); //$NON-NLS-1$
interfaze.addMethod(newMethod);
interfaze.addImportedType(rowBounds);
}
代码示例来源:origin: org.mybatis.generator/mybatis-generator-core
private void addNewComposedFunction(Interface interfaze, IntrospectedTable introspectedTable, FullyQualifiedJavaType baseMethodReturnType) {
interfaze.addImportedType(new FullyQualifiedJavaType("java.util.function.Function")); //$NON-NLS-1$
FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("Function<SelectStatementProvider, " //$NON-NLS-1$
+ baseMethodReturnType.getShortName() + ">"); //$NON-NLS-1$
Method method = new Method("selectManyWithRowbounds"); //$NON-NLS-1$
method.setDefault(true);
method.setReturnType(returnType);
method.addParameter(new Parameter(rowBounds, "rowBounds")); //$NON-NLS-1$
method.addBodyLine("return selectStatement -> selectManyWithRowbounds(selectStatement, rowBounds);"); //$NON-NLS-1$
context.getCommentGenerator().addGeneralMethodAnnotation(method, introspectedTable, interfaze.getImportedTypes());
interfaze.addMethod(method);
}
代码示例来源:origin: beihaifeiwu/dolphin
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
String objectName = introspectedTable.getTableConfiguration().getDomainObjectName();
Method method = new Method(BATCH_INSERT);
FullyQualifiedJavaType type = new FullyQualifiedJavaType("java.util.List<" + objectName + ">");
method.addParameter(new Parameter(type, "list"));
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
interfaze.addMethod(method);
return true;
}
代码示例来源:origin: dcendents/mybatis-generator-plugins
@Override
public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass,
IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
if (tableMatches(introspectedTable) && settersToWrap.contains(method.getName())) {
method.getBodyLines().clear();
method.addBodyLine(String.format("this.%s.%s(%s);", objectFieldName, method.getName(), method
.getParameters().get(0).getName()));
}
return true;
}
代码示例来源:origin: dcendents/mybatis-generator-plugins
Method addMethod(Method method, IntrospectedTable introspectedTable) {
IntrospectedColumn column = getColumn(introspectedTable);
Method withLock = new Method(method);
withLock.setName(method.getName() + METHOD_SUFFIX);
withLock.getAnnotations().clear();
for (String line : method.getAnnotations()) {
if (line.matches("\\s*\".*\"\\s*")) {
withLock.getAnnotations().add(line + ",");
String typeHandler = column.getTypeHandler() != null ? String.format(",typeHandler=%s", column.getTypeHandler()) : "";
withLock.getAnnotations().add(String.format(" \"and %1$s = #{%2$s,jdbcType=%3$s%4$s}\"", lockColumnFunction,
column.getJavaProperty(), column.getJdbcTypeName(), typeHandler));
} else {
withLock.getAnnotations().add(line);
}
}
return withLock;
}
代码示例来源:origin: org.mybatis.generator/mybatis-generator-core
private void copyAndAddSelectByExampleMethodForDSQL(Method method, Interface interfaze) {
Method newMethod = new Method(method);
newMethod.addParameter(new Parameter(rowBounds, "rowBounds")); //$NON-NLS-1$
interfaze.addMethod(newMethod);
interfaze.addImportedType(rowBounds);
// replace the call to selectMany with the new call to selectManyWithRowbounds
for (int i = 0; i < newMethod.getBodyLines().size(); i++) {
String bodyLine = newMethod.getBodyLines().get(i);
if (bodyLine.contains("this::selectMany")) { //$NON-NLS-1$
bodyLine = bodyLine.replace("this::selectMany", //$NON-NLS-1$
"selectManyWithRowbounds(rowBounds)"); //$NON-NLS-1$
newMethod.getBodyLines().set(i, bodyLine);
break;
}
}
}
代码示例来源:origin: abel533/Mapper
/**
* getter方法注释
*
* @param method
* @param introspectedTable
* @param introspectedColumn
*/
@Override
public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**");
if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
sb.append(" * 获取");
sb.append(introspectedColumn.getRemarks());
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" *");
}
sb.setLength(0);
sb.append(" * @return ");
sb.append(introspectedColumn.getActualColumnName());
if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
sb.append(" - ");
sb.append(introspectedColumn.getRemarks());
}
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" */");
}
代码示例来源:origin: dcendents/mybatis-generator-plugins
boolean renameMethod(Method method) {
String oldMethodName = method.getName();
Matcher matcher = classMethodPattern.matcher(oldMethodName);
String newMethodName = matcher.replaceAll(classMethodReplaceString);
method.setName(newMethodName);
for (int i = 0; i < method.getParameters().size(); i++) {
Parameter parameter = method.getParameters().get(i);
String oldParamName = parameter.getName();
matcher = parameterPattern.matcher(oldParamName);
if (matcher.lookingAt()) {
String newName = matcher.replaceAll(parameterReplaceString);
Parameter newParam = new Parameter(parameter.getType(), newName, parameter.isVarargs());
for (String annotation : parameter.getAnnotations()) {
newParam.addAnnotation(annotation);
}
method.getParameters().set(i, newParam);
}
}
return true;
}
代码示例来源:origin: MisterChangRay/mybatis-generator-plugins
@Override
public boolean modelSetterMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
method.setReturnType(topLevelClass.getType());
method.addBodyLine("return this;");
logger.debug("Setter扩展完成");
return super.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
}
内容来源于网络,如有侵权,请联系作者删除!