父親:
public class BaseController<T> {
@PostMapping
public ResponseValue add(HttpServletRequest req, @Validated({DeleteValid.class}) T entity) throws Exception {
return service.add(req, entity);
}
@GetMapping
public ResponseValue searchList(HttpServletRequest req, T entity,
@RequestParam(defaultValue = "1",required = false) int page,
@RequestParam(defaultValue = "10",required = false)int size) throws Exception {
return service.searchList(req, entity, page, size);
}
@DeleteMapping
public ResponseValue delete(HttpServletRequest req, @Validated({DeleteValid.class}) T entity) throws Exception {
return service.delete(req, entity);
}
@PutMapping
public ResponseValue edit(HttpServletRequest req,@Validated({UpdateValid.class}) T entity) throws Exception {
return service.edit(req, entity);
}
}
サブクラス:
@RequestMapping("/sys/control/list")
public class SystemCtrlMobileBlackColorListController extends BaseController<CtrlMobileColorlist> {
@Override
public ResponseValue add(HttpServletRequest req, CtrlMobileColorlist entity) throws Exception {
reuturn null;
}
@Override
public ResponseValue searchList(HttpServletRequest req, CtrlMobileColorlist entity,
@RequestParam(defaultValue = "1", required = false) int page,
@RequestParam(defaultValue = "10", required = false) int size) throws Exception {
reuturn null;
}
@Override
public ResponseValue delete(HttpServletRequest req, CtrlMobileColorlist entity) throws Exception {
entity.setType(CommonConstant.MOBILE_COLOR_TYPE_BLACK_SYSTEM);
return ctrlMobileColorlistService.delete(req, entity);
}
@Override
public ResponseValue edit(HttpServletRequest req, @Validated({UpdateValid.class}) CtrlMobileColorlist entity) throws Exception {
entity.setType(CommonConstant.MOBILE_COLOR_TYPE_BLACK_SYSTEM);
return ctrlMobileColorlistService.edit(req, entity);
}
}
リクエスト アドレスのリクエスト メソッドに応じて、リクエストされるインターフェイスが自動的に選択されます。get リクエストでは searchList メソッドをリクエストでき、その他のリクエストでは他のメソッドを使用します。
例:
https://tt.test.com/sys/control/list?token=qqq&category=&type=-2&order=create_time:desc&page=1&size =10 デフォルトのリクエストの searchList メソッド