代码生成器
importcom.baomidou.mybatisplus.generator.FastAutoGenerator; importcom.baomidou.mybatisplus.generator.config.OutputFile; importjava.util.Collections; publicclassGenerator { publicstaticvoidmain(String[] args) { generate(); } publicstaticvoidgenerate(){ FastAutoGenerator.create("jdbc:mysql://rm-bp196c1cs9f1wt0f79o.mysql.rds.aliyuncs.com:3306/juesai", "xiaomr", "jsepc123!") .globalConfig(builder-> { builder.fileOverride() // 覆盖已生成文件 .outputDir("G:\\springboot\\juesai2\\src\\main\\java"); // 指定输出目录 }) .packageConfig(builder-> { builder.parent("com.zxb.juesai2") // 设置父包名 .moduleName(null) // 设置父包模块名 .pathInfo(Collections.singletonMap(OutputFile.xml, "G:\\springboot\\juesai2\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径 }) .strategyConfig(builder-> { builder.addInclude("admin") // 设置需要生成的表名 .addTablePrefix("t_", "c_"); // 设置过滤表前缀 }) // .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 .execute(); } }
分页查询配置类
importcom.baomidou.mybatisplus.annotation.DbType; importcom.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; importcom.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; importorg.springframework.context.annotation.Bean; importorg.springframework.context.annotation.Configuration; publicclassMybatisPlusConfig { publicMybatisPlusInterceptormybatisPlusInterceptor(){ MybatisPlusInterceptormybatisPlusInterceptor=newMybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(newPaginationInnerInterceptor(DbType.MYSQL)); returnmybatisPlusInterceptor; } }