Skip to content

Commit d877b48

Browse files
committed
Update controller.ftl
1 parent 4f606ee commit d877b48

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

generator/src/main/resources/template/controller.ftl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import io.swagger.annotations.Api;
44
import io.swagger.annotations.ApiImplicitParam;
55
import io.swagger.annotations.ApiImplicitParams;
66
import io.swagger.annotations.ApiOperation;
7+
import lazy.fast.code.core.exception.NoContentNotException;
8+
import lazy.fast.code.core.exception.NotFoundException;
79
import lazy.fast.code.core.orm.BaseController;
810
import lazy.fast.code.core.orm.BaseService;
911
import org.springframework.http.ResponseEntity;
12+
import org.springframework.util.CollectionUtils;
1013
import org.springframework.web.bind.annotation.DeleteMapping;
1114
import org.springframework.web.bind.annotation.GetMapping;
1215
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,14 +40,22 @@ public class ${className?cap_first}Controller extends BaseController<${className
3740
@ApiOperation(value = "获取${classDescription}列表")
3841
@GetMapping
3942
public List<${className?cap_first}> list(${className?cap_first} ${className?uncap_first}) {
40-
return this.getBaseService().list(${className?uncap_first});
43+
List<${className?cap_first}> list = this.getBaseService().list(${className?uncap_first});
44+
if (CollectionUtils.isEmpty(list)) {
45+
throw new NoContentNotException();
46+
}
47+
return list;
4148
}
4249

4350
@ApiOperation(value = "根据数据主键获取${classDescription}")
4451
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "数据主键", required = true, paramType = "path")})
4552
@GetMapping("/{id}")
4653
public ${className?cap_first} get(@PathVariable String id) {
47-
return this.getBaseService().get(id);
54+
${className?cap_first} ${className?uncap_first} = this.getBaseService().get(id);
55+
if (${className?uncap_first} == null) {
56+
throw new NotFoundException();
57+
}
58+
return ${className?uncap_first};
4859
}
4960

5061
@ApiOperation(value = "保存${classDescription}")

0 commit comments

Comments
 (0)