<!-- 代码生成器依赖--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.6.2</version> </dependency> </dependencies>
controller层增删改查分页
package ${package.Controller}; import org.apache.ibatis.annotations.Update; import org.springframework.web.bind.annotation.*; import java.util.List; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import javax.annotation.Resource; import org.springframework.web.bind.annotation.RequestMapping; import ${package.Service}.${table.serviceName}; import ${package.Entity}.${entity}; #if(${restControllerStyle}) import org.springframework.web.bind.annotation.RestController; #else import org.springframework.stereotype.Controller; #end #if(${superControllerClassPackage}) import ${superControllerClassPackage}; #end /** * <p> * $!{table.comment} 前端控制器 * </p> * * @author ${author} * @since ${date} */ #if(${restControllerStyle}) @RestController #else @Controller #end @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") #if(${kotlin}) class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end #else #if(${superControllerClass}) public class ${table.controllerName} extends ${superControllerClass} { #else public class ${table.controllerName} { #end @Resource private ${table.serviceName} ${table.entityPath}Service; //新增或者更新 @PostMapping("/saveOrUpdate") public boolean save(@RequestBody ${entity} ${table.entityPath}){ return ${table.entityPath}Service.saveOrUpdate(${table.entityPath}); } //删除单个 @DeleteMapping("/del/{id}") public boolean delete(@PathVariable Integer id){ return ${table.entityPath}Service.removeById(id); } //批量删除 @DeleteMapping("/dels/{ids}") public boolean delete(@PathVariable List<List> ids){ return ${table.entityPath}Service.removeByIds(ids); } //修改 @PostMapping("/update") public boolean update(@RequestBody ${entity} ${table.entityPath}){ return ${table.entityPath}Service.update(${table.entityPath},null); } //查找全部 @GetMapping("/findAll") public List<${entity}> findAll(){ return ${table.entityPath}Service.list(); } //单个查找 @GetMapping("/findOne") public ${entity} findOne(@PathVariable Integer id){ return ${table.entityPath}Service.getById(id); } //分页 @GetMapping("/page") public Page<${entity}> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){ QueryWrapper<User> queryWrapper = new QueryWrapper<>(); return ${table.entityPath}Service.page(new Page<>(pageNum,pageSize),queryWrapper); } } #end
mp Main
/mp代码生成器 public class CodeGenerator { public static void main(String[] args) { generator(); } public static void generator(){ FastAutoGenerator.create("jdbc:mysql://localhost:3306/bootvue01?useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8", "root", "123") .globalConfig(builder -> { builder.author("shuchong") // 设置作者 .enableSwagger() // 开启 swagger 模式 .fileOverride() // 覆盖已生成文件 .outputDir("D:\\giteecloneproj\\boot_vue01\\src\\main\\java\\"); // 指定输出目录 }) .packageConfig(builder -> { builder.parent("com.boot") // 设置父包名 .moduleName(null) // 设置父包模块名 .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\giteecloneproj\\boot_vue01\\src\\java\\resources\\mapper\\")); // 设置mapperXml生成路径 }) .strategyConfig(builder -> { builder.addInclude("sys_user") // 设置需要生成的表名 .addTablePrefix("t_", "sys_"); // 设置过滤表前缀 }) // .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 .execute(); } }