网站专题报道怎么做,模拟装修效果的软件,高端的网站制作,三渡网络推广培训mybatis结合generator生成的代码没有分页的功能#xff0c;可以尝试自己继承分页插件PluginAdapter#xff0c;进行开发#xff0c;实现自己的分页插件这样generator生产的代码 带分页功能了。
MyBatis MySQL自动生成带分页插件
继承PluginAdapter类#xff0c;实现相关方…mybatis结合generator生成的代码没有分页的功能可以尝试自己继承分页插件PluginAdapter进行开发实现自己的分页插件这样generator生产的代码 带分页功能了。
MyBatis MySQL自动生成带分页插件
继承PluginAdapter类实现相关方法 /*** MyBatis MySQL自动生成带分页插件* * author */
public class MysqlPaginationPlugin extends PluginAdapter {Overridepublic boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {addLimit(topLevelClass, introspectedTable, limitStart);addLimit(topLevelClass, introspectedTable, limitSize);return super.modelExampleClassGenerated(topLevelClass, introspectedTable);}/*** 为selectByExample添加limitStart和limitSize*/Overridepublic boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element,IntrospectedTable introspectedTable) {XmlElement isNotNullElement new XmlElement(if);isNotNullElement.addAttribute(new Attribute(test, limitStart ! null and limitSize 0));isNotNullElement.addElement(new TextElement(limit #{limitStart} , #{limitSize}));element.addElement(isNotNullElement);return super.sqlMapSelectByExampleWithoutBLOBsElementGenerated(element, introspectedTable);}/*** 为selectByExampleWithBLOBs添加limitStart和limitSize*/Overridepublic boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element,IntrospectedTable introspectedTable) {XmlElement isNotNullElement new XmlElement(if);isNotNullElement.addAttribute(new Attribute(test, limitStart ! null and limitSize 0));isNotNullElement.addElement(new TextElement(limit #{limitStart} , #{limitSize}));element.addElement(isNotNullElement);return super.sqlMapSelectByExampleWithBLOBsElementGenerated(element, introspectedTable);}private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) {CommentGenerator commentGenerator context.getCommentGenerator();/*** 创建类成员变量 如protected Integer limitStart;*/Field field new Field();field.setVisibility(JavaVisibility.PROTECTED);field.setType(PrimitiveTypeWrapper.getIntegerInstance());field.setName(name);commentGenerator.addFieldComment(field, introspectedTable);topLevelClass.addField(field);/*** 首字母大写*/char c name.charAt(0);String camel Character.toUpperCase(c) name.substring(1);/*** 添加Setter方法*/Method method new Method();method.setVisibility(JavaVisibility.PUBLIC);method.setName(set camel);method.addParameter(new Parameter(PrimitiveTypeWrapper.getIntegerInstance(), name));StringBuilder sb new StringBuilder();sb.append(this.);sb.append(name);sb.append( );sb.append(name);sb.append(;);/*** 如 this.limitStart limitStart;*/method.addBodyLine(sb.toString());commentGenerator.addGeneralMethodComment(method, introspectedTable);topLevelClass.addMethod(method);/*** 添加Getter Method 直接调用AbstractJavaGenerator的getGetter方法*/Method getterMethod AbstractJavaGenerator.getGetter(field);commentGenerator.addGeneralMethodComment(getterMethod, introspectedTable);topLevelClass.addMethod(getterMethod);}public boolean validate(ListString warnings) {return true;}public static void generate() {String config PaginationMysqlPlugin.class.getClassLoader().getResource(generatorConfig.xml).getFile();String[] arg { -configfile, config, -overwrite };ShellRunner.main(arg);}public static void main(String[] args) {generate();}}