# template **Repository Path**: ubuntu-maxfeng/template ## Basic Information - **Project Name**: template - **Description**: template - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-03-12 - **Last Updated**: 2022-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ##敏捷的Spring项目模板 项目基础思维:简洁开发 基础技术选型:Spring系列
权限检测:
1 Shiro -> Apache
2 Verify -> smartcase.base.auth
DB选型:
1 MySQL -> MybatisPlus
2 MongoDB -> smartcase.base.mongo(自己封装的库)
基础框架:
1 Lombok -> 避免人为写get/set方法
2 Guava -> JDK增强库,建议使用Executors(线程池增强)/ImmutableCollection(数据并发安全保证)/Iteration(快速迭代集合)
3 Validator -> 建议统一Controller层入参检测,避免人为编写If/else判断入参合法
日志框架:
1 Lombok -> 统一采用自主封装的Lombok,好处有自定义日志采集逻辑
建议规范1:为避免java NPE多空指针特点,方法互相调用返回值选择Optional
``` public interface CheckHealthService { Optional getProjectById(String id); } // 降低NPE方式 Optional optional = checkHealthService.getProjectById("a"); String hookName = optional.map(t -> t.getHook()).map(t -> t.getName()).orElse(""); ``` 建议规范2:建议统一Controller写法,入参选择在dto包下创建对应的request对象,出参选择dto包下的response对象,request和response对象自建,Controller返回值统一选择,ok/error方法进行包装错误, 并且controller入参第一个写CommonInfo,CommonInfo经过Access层进行包装,通过CommonInfo实现调用链路日志的收集,开发者无需关心此参数
``` @PostMapping(value = "/health/check") @Verify public ApiResponse checkHealth(CommonInfo cInfo, @RequestBody CheckHealthRequest request){ CheckHealthResponse response = new CheckHealthResponse(); response.setIsHealth(true); response.setServerIP("localhost"); return ok(response); } @PostMapping(value = "/health/check1") @Verify public ApiResponse checkHealth1(CommonInfo cInfo,@RequestBody CheckHealthRequest request){ CheckHealthResponse response = new CheckHealthResponse(); response.setIsHealth(true); response.setServerIP("localhost"); return error(ApiStandard.INTERNAL_SERVER_ERROR); } ``` 规范建议3:建议参数检测统一使用Validator降低If、else代码量
``` @Data public class CheckHealthRequest implements Request { @NotBlank(message = "callParam不可为空") private String callParam; private String echoName; @Min(message = "echoValue最大是1",value = 1) @Max(message = "echoValue最大是10", value = 10) private Integer echoValue; } ``` 规范建议4:代码格式化建议:建议idea安装google-java-format插件并开启enable
规范建议3:Git规范建议(尽可能降低代码冲突的风险) 1 一个新特性一个分支,合并完dev和master进行删除 2 开发者新创建的分支建议在合并master时压缩为一个commit 3 分支命名建议feature/xxxx 操作手册 ``` 创建分支 git clone https://.... -b master git checkout -b feature/xxxx git add . git commit -m "comment" git push origin feature/xxxx 合并分支(每次在合并分支时先rebase下master查看是否存在冲突) git rebase -i master git rebase -i HEAD~2(压缩commit) ``` - ```git clone https://github.com/Maple-mxf/smartspringcase.git -b main``` - ```mvn clean install``` - 项目配置尚不完整,靠你来完善了~~~