feat(board-generator): add board code generator and sample CRUD artifacts
Add Node.js CLI tool with Handlebars templates for generating standard CRUD artifacts: Java entity, service, DAO, controller, MyBatis mapper XML, and Vue frontend pages. Also generate the full SampleTableBoard CRUD reference implementation, update README with backend execution instructions, and add project plan documentation.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package {{controllerPackage}};
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
{{#each controllerImports}}
|
||||
import {{this}};
|
||||
{{/each}}
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import {{rootPackage}}.{{serviceName}};
|
||||
import {{entityFqcn}};
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("{{requestBasePath}}")
|
||||
@Log4j2
|
||||
public class {{controllerName}} {
|
||||
|
||||
private final {{serviceName}} {{entityVarName}}Service;
|
||||
|
||||
public {{controllerName}}({{serviceName}} {{entityVarName}}Service) {
|
||||
|
||||
this.{{entityVarName}}Service = {{entityVarName}}Service;
|
||||
}
|
||||
|
||||
@Operation(summary = "page 초기정보.")
|
||||
@PostMapping(value = "list/main.do", params = "method=page")
|
||||
public Map<String, Object> page(@RequestBody Map<String, Object> params) throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("menuName", "{{menuName}}");
|
||||
result.put("result", {{entityVarName}}Service.get{{entityName}}List());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "{{menuName}} 목록 조회")
|
||||
@PostMapping(value = "list/main.do", params = "method=search")
|
||||
public Map<String, Object> list_search(@RequestBody Map<String, Object> params) throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("result", {{entityVarName}}Service.get{{entityName}}List());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "{{menuName}} 상세 조회")
|
||||
@PostMapping(value = "item/main.do", params = "method=get{{entityName}}")
|
||||
public Map<String, Object> item_get{{entityName}}(@RequestBody Map<String, Object> params) throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("result", {{entityVarName}}Service.get{{entityName}}(getPrimaryKey(params)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "{{menuName}} 등록")
|
||||
@PostMapping(value = "item/main.do", params = "method=regist")
|
||||
public Map<String, Object> item_regist(@RequestBody {{entityName}} {{entityVarName}}) throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("result", {{entityVarName}}Service.create{{entityName}}({{entityVarName}}));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "{{menuName}} 수정")
|
||||
@PostMapping(value = "item/main.do", params = "method=update")
|
||||
public Map<String, Object> item_update(@RequestBody {{entityName}} {{entityVarName}}) throws Exception {
|
||||
|
||||
if ({{entityVarName}}.{{primaryKeyGetterName}}() == null) {
|
||||
throw new IllegalArgumentException("{{primaryKeyProperty}} 값은 필수입니다.");
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("result", {{entityVarName}}Service.update{{entityName}}({{entityVarName}}));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "{{menuName}} 삭제")
|
||||
@PostMapping(value = "item/main.do", params = "method=delete")
|
||||
public String item_delete(@RequestBody Map<String, Object> params) throws Exception {
|
||||
|
||||
{{entityVarName}}Service.delete{{entityName}}(getPrimaryKey(params));
|
||||
return "success";
|
||||
}
|
||||
|
||||
private {{primaryKeyJavaType}} getPrimaryKey(Map<String, Object> params) {
|
||||
|
||||
if (params == null || params.get("{{primaryKeyProperty}}") == null) {
|
||||
throw new IllegalArgumentException("{{primaryKeyProperty}} 값은 필수입니다.");
|
||||
}
|
||||
|
||||
String value = params.get("{{primaryKeyProperty}}").toString();
|
||||
return {{primaryKeyParseExpression}};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user