feat: code gen
This commit is contained in:
@@ -18,11 +18,20 @@ import java.util.Collections;
|
||||
*/
|
||||
public class GenPlusUtils {
|
||||
|
||||
// 生成代码输出路径
|
||||
public static final String OUTPUT_PATH = "D://gencode/test4";
|
||||
// 模块名:system/user
|
||||
public static final String MODULE_NAME = "system";
|
||||
// 数据库URL
|
||||
public static final String URL = "jdbc:mysql://localhost:3306/wfc_system_db?useUnicode=true&useSSL=false&characterEncoding=utf8";
|
||||
// 表名
|
||||
public static final String TABLE_NAME = "sys_rate_limit";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
FastAutoGenerator.create("jdbc:mysql://localhost:3306/wfc-user-db?useUnicode=true&useSSL=false&characterEncoding=utf8", "root", "123456")
|
||||
FastAutoGenerator.create(URL, "root", "123456")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("cyc") // 设置作者
|
||||
builder.author("sys") // 设置作者
|
||||
.enableSpringdoc()
|
||||
.dateType(DateType.ONLY_DATE)
|
||||
.outputDir("D://gencode"); // 指定输出目录
|
||||
@@ -43,7 +52,7 @@ public class GenPlusUtils {
|
||||
)
|
||||
.packageConfig(builder ->
|
||||
builder.parent("org.wfc") // 设置父包名
|
||||
.moduleName("user") // 设置父包模块名
|
||||
.moduleName(MODULE_NAME) // 设置父包模块名
|
||||
.entity("domain")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, "D://gencode")) // 设置mapperXml生成路径
|
||||
)
|
||||
@@ -63,6 +72,8 @@ public class GenPlusUtils {
|
||||
.addTableFills(new Column("update_by", FieldFill.INSERT_UPDATE))
|
||||
.controllerBuilder()
|
||||
.enableRestStyle()
|
||||
.template("/templates/controller.java.vm")
|
||||
.enableFileOverride()
|
||||
.serviceBuilder()
|
||||
.enableFileOverride()
|
||||
.mapperBuilder()
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#set(${serviceName} = "${table.serviceName.substring(1, 2).toLowerCase()}${table.serviceName.substring(2)}")
|
||||
#set($entityName = "${entity.substring(0, 1).toLowerCase()}${entity.substring(1)}")
|
||||
package ${package.Controller};
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.wfc.common.core.web.controller.BaseController;
|
||||
import org.wfc.common.core.web.domain.AjaxResult;
|
||||
import org.wfc.common.core.web.page.TableDataInfo;
|
||||
import org.wfc.system.domain.SysRateLimit;
|
||||
import org.wfc.system.service.ISysRateLimitService;
|
||||
|
||||
import java.util.List;
|
||||
#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} extends BaseController {
|
||||
#end
|
||||
|
||||
@Autowired
|
||||
public ${table.serviceName} ${serviceName};
|
||||
|
||||
@GetMapping("/page")
|
||||
public TableDataInfo page(${entity} $entityName) {
|
||||
startPage();
|
||||
List<${entity}> list = ${serviceName}.list();
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(${entity} $entityName) {
|
||||
List<${entity}> list = ${serviceName}.list();
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getById(@PathVariable("id") Long id) {
|
||||
return success(${serviceName}.getById(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ${entity} $entityName) {
|
||||
return toAjax(${serviceName}.save($entityName));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ${entity} $entityName) {
|
||||
return toAjax(${serviceName}.updateById($entityName));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(${serviceName}.removeByIds(CollUtil.newArrayList(ids)));
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
Reference in New Issue
Block a user