Skip to content

Commit 81d55a5

Browse files
committed
修改代码规范,if for try空格添加,代码更美观
1 parent 0bda6bb commit 81d55a5

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/test/java/com/example/generator/CodeGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ public static void genModelAndMapper(String tableName, String modelName) {
156156
if (generator.getGeneratedJavaFiles().isEmpty() || generator.getGeneratedXmlFiles().isEmpty()) {
157157
throw new RuntimeException("生成Model和Mapper失败:" + warnings);
158158
}
159-
if (StringUtils.isEmpty(modelName)) modelName = tableNameConvertUpperCamel(tableName);
159+
if (StringUtils.isEmpty(modelName)) {
160+
modelName = tableNameConvertUpperCamel(tableName);
161+
}
160162
System.out.println(modelName + ".java 生成成功");
161163
System.out.println(modelName + "Mapper.java 生成成功");
162164
System.out.println(modelName + "Mapper.xml 生成成功");
@@ -221,9 +223,9 @@ public static void genController(String tableName, String modelName) {
221223
if (!file.getParentFile().exists()) {
222224
file.getParentFile().mkdirs();
223225
}
224-
if("POST".equals(CONTROLLER_TYPE)){
226+
if ("POST".equals(CONTROLLER_TYPE)) {
225227
cfg.getTemplate("controller.ftl").process(data, new FileWriter(file));
226-
}else{
228+
} else {
227229
cfg.getTemplate("controller-restful.ftl").process(data, new FileWriter(file));
228230
}
229231

src/test/resources/template/controller-restful.ftl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class ${modelNameUpperCamel}Controller {
3737
*/
3838
@GetMapping
3939
public ResponseBean list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
40-
if(page <= 0 || rows <= 0){
40+
if (page <= 0 || rows <= 0) {
4141
page = 1;
4242
rows = 10;
4343
}
4444
PageHelper.startPage(page, rows);
4545
List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.selectAll();
46-
if(list == null || list.size() <= 0){
46+
if (list == null || list.size() <= 0) {
4747
throw new CustomException("查询失败(Query Failure)");
4848
}
4949
PageInfo<${modelNameUpperCamel}> pageInfo = new PageInfo<${modelNameUpperCamel}>(list);
@@ -61,7 +61,7 @@ public class ${modelNameUpperCamel}Controller {
6161
@GetMapping("/{id}")
6262
public ResponseBean detail(@PathVariable Integer id) {
6363
${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.selectByPrimaryKey(id);
64-
if(${modelNameLowerCamel} == null){
64+
if (${modelNameLowerCamel} == null) {
6565
throw new CustomException("查询失败(Query Failure)");
6666
}
6767
return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", ${modelNameLowerCamel});
@@ -75,7 +75,7 @@ public class ${modelNameUpperCamel}Controller {
7575
@PostMapping
7676
public ResponseBean add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
7777
int count = ${modelNameLowerCamel}Service.insert(${modelNameLowerCamel});
78-
if(count <= 0){
78+
if (count <= 0) {
7979
throw new CustomException("新增失败(Insert Failure)");
8080
}
8181
return new ResponseBean(200, "新增成功(Insert Success)", ${modelNameLowerCamel});
@@ -89,7 +89,7 @@ public class ${modelNameUpperCamel}Controller {
8989
@PutMapping
9090
public ResponseBean update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
9191
int count = ${modelNameLowerCamel}Service.updateByPrimaryKeySelective(${modelNameLowerCamel});
92-
if(count <= 0){
92+
if (count <= 0) {
9393
throw new CustomException("更新失败(Update Failure)");
9494
}
9595
return new ResponseBean(200, "更新成功(Update Success)", ${modelNameLowerCamel});
@@ -103,7 +103,7 @@ public class ${modelNameUpperCamel}Controller {
103103
@DeleteMapping("/{id}")
104104
public ResponseBean delete(@PathVariable Integer id) {
105105
int count = ${modelNameLowerCamel}Service.deleteByPrimaryKey(id);
106-
if(count <= 0){
106+
if (count <= 0) {
107107
throw new CustomException("删除失败,ID不存在(Deletion Failed. ID does not exist.)");
108108
}
109109
return new ResponseBean(200, "删除成功(Delete Success)", null);

src/test/resources/template/controller.ftl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class ${modelNameUpperCamel}Controller {
3737
*/
3838
@PostMapping("/list")
3939
public ResponseBean list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
40-
if(page <= 0 || rows <= 0){
40+
if (page <= 0 || rows <= 0) {
4141
page = 1;
4242
rows = 10;
4343
}
4444
PageHelper.startPage(page, rows);
4545
List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.selectAll();
46-
if(list == null || list.size() <= 0){
46+
if (list == null || list.size() <= 0) {
4747
throw new CustomException("查询失败(Query Failure)");
4848
}
4949
PageInfo<${modelNameUpperCamel}> pageInfo = new PageInfo<${modelNameUpperCamel}>(list);
@@ -61,7 +61,7 @@ public class ${modelNameUpperCamel}Controller {
6161
@PostMapping("/detail")
6262
public ResponseBean detail(@RequestParam Integer id) {
6363
${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.selectByPrimaryKey(id);
64-
if(${modelNameLowerCamel} == null){
64+
if (${modelNameLowerCamel} == null) {
6565
throw new CustomException("查询失败(Query Failure)");
6666
}
6767
return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", ${modelNameLowerCamel});
@@ -75,7 +75,7 @@ public class ${modelNameUpperCamel}Controller {
7575
@PostMapping("/add")
7676
public ResponseBean add(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
7777
int count = ${modelNameLowerCamel}Service.insert(${modelNameLowerCamel});
78-
if(count <= 0){
78+
if (count <= 0) {
7979
throw new CustomException("新增失败(Insert Failure)");
8080
}
8181
return new ResponseBean(200, "新增成功(Insert Success)", ${modelNameLowerCamel});
@@ -89,7 +89,7 @@ public class ${modelNameUpperCamel}Controller {
8989
@PostMapping("/update")
9090
public ResponseBean update(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
9191
int count = ${modelNameLowerCamel}Service.updateByPrimaryKeySelective(${modelNameLowerCamel});
92-
if(count <= 0){
92+
if (count <= 0) {
9393
throw new CustomException("更新失败(Update Failure)");
9494
}
9595
return new ResponseBean(200, "更新成功(Update Success)", ${modelNameLowerCamel});
@@ -103,7 +103,7 @@ public class ${modelNameUpperCamel}Controller {
103103
@PostMapping("/delete")
104104
public ResponseBean delete(@RequestParam Integer id) {
105105
int count = ${modelNameLowerCamel}Service.deleteByPrimaryKey(id);
106-
if(count <= 0){
106+
if (count <= 0) {
107107
throw new CustomException("删除失败,ID不存在(Deletion Failed. ID does not exist.)");
108108
}
109109
return new ResponseBean(200, "删除成功(Delete Success)", null);

0 commit comments

Comments
 (0)