接口使用@requestMapping应用场景

2023-12-14 12:29:47

父类:

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方法

文章来源:https://blog.csdn.net/weixin_44060488/article/details/134991256
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。