2222import io .swagger .v3 .oas .annotations .Parameter ;
2323import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
2424import jakarta .servlet .http .HttpServletResponse ;
25+ import jakarta .validation .Valid ;
2526import org .springframework .beans .factory .annotation .Autowired ;
2627import org .springframework .validation .annotation .Validated ;
2728import org .springframework .web .bind .annotation .*;
@@ -65,7 +66,7 @@ public abstract class AbstractCrudController<S extends CrudService<L, D, Q, C>,
6566 @ Operation (summary = "分页查询列表" , description = "分页查询列表" )
6667 @ ResponseBody
6768 @ GetMapping
68- public BasePageResp <L > page (@ Validated Q query , @ Validated PageQuery pageQuery ) {
69+ public BasePageResp <L > page (@ Valid Q query , @ Valid PageQuery pageQuery ) {
6970 return baseService .page (query , pageQuery );
7071 }
7172
@@ -80,7 +81,7 @@ public BasePageResp<L> page(@Validated Q query, @Validated PageQuery pageQuery)
8081 @ Operation (summary = "查询列表" , description = "查询列表" )
8182 @ ResponseBody
8283 @ GetMapping ("/list" )
83- public List <L > list (@ Validated Q query , @ Validated SortQuery sortQuery ) {
84+ public List <L > list (@ Valid Q query , @ Valid SortQuery sortQuery ) {
8485 return baseService .list (query , sortQuery );
8586 }
8687
@@ -95,7 +96,7 @@ public List<L> list(@Validated Q query, @Validated SortQuery sortQuery) {
9596 @ Operation (summary = "查询树列表" , description = "查询树列表" )
9697 @ ResponseBody
9798 @ GetMapping ("/tree" )
98- public List <Tree <Long >> tree (@ Validated Q query , @ Validated SortQuery sortQuery ) {
99+ public List <Tree <Long >> tree (@ Valid Q query , @ Valid SortQuery sortQuery ) {
99100 return baseService .tree (query , sortQuery , false );
100101 }
101102
@@ -124,7 +125,8 @@ public D get(@PathVariable("id") Long id) {
124125 @ Operation (summary = "创建数据" , description = "创建数据" )
125126 @ ResponseBody
126127 @ PostMapping
127- public IdResp <Long > create (@ Validated (CrudValidationGroup .Create .class ) @ RequestBody C req ) {
128+ @ Validated (CrudValidationGroup .Create .class )
129+ public IdResp <Long > create (@ RequestBody @ Valid C req ) {
128130 return new IdResp <>(baseService .create (req ));
129131 }
130132
@@ -139,7 +141,8 @@ public IdResp<Long> create(@Validated(CrudValidationGroup.Create.class) @Request
139141 @ Parameter (name = "id" , description = "ID" , example = "1" , in = ParameterIn .PATH )
140142 @ ResponseBody
141143 @ PutMapping ("/{id}" )
142- public void update (@ Validated (CrudValidationGroup .Update .class ) @ RequestBody C req , @ PathVariable ("id" ) Long id ) {
144+ @ Validated (CrudValidationGroup .Update .class )
145+ public void update (@ RequestBody @ Valid C req , @ PathVariable ("id" ) Long id ) {
143146 baseService .update (req , id );
144147 }
145148
@@ -166,7 +169,7 @@ public void delete(@PathVariable("id") Long id) {
166169 @ Operation (summary = "批量删除数据" , description = "批量删除数据" )
167170 @ ResponseBody
168171 @ DeleteMapping
169- public void batchDelete (@ Validated @ RequestBody IdsReq req ) {
172+ public void batchDelete (@ RequestBody @ Valid IdsReq req ) {
170173 baseService .delete (req .getIds ());
171174 }
172175
@@ -181,7 +184,7 @@ public void batchDelete(@Validated @RequestBody IdsReq req) {
181184 @ ExcludeFromGracefulResponse
182185 @ Operation (summary = "导出数据" , description = "导出数据" )
183186 @ GetMapping ("/export" )
184- public void export (@ Validated Q query , @ Validated SortQuery sortQuery , HttpServletResponse response ) {
187+ public void export (@ Valid Q query , @ Valid SortQuery sortQuery , HttpServletResponse response ) {
185188 baseService .export (query , sortQuery , response );
186189 }
187190}
0 commit comments