多种前后端传值方式

tech2023-02-11  116

1.@RequestParam

@PostMapping(value = "/getMarkersPosition") public Result<List<ServeWorkorder>> getMarkersPosition( HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "month", required = true) String month ) { } export const getMarkersPosition = params =>{ return request({ url: url + "/serve/workOrderMap/getMarkersPosition", method: "post", params }); }; getMarkersPosition({month:this.valueOfTime}).then(res => { })

传值时url: 在postMan中要选择body的类型为 x-www-form-urlencoded

2.@RequestBody

@PostMapping(value="/save") public Result<PersonnelDeptInfo> save( HttpServletRequest request, HttpServletResponse response, @RequestBody PersonnelDeptInfo personnelDeptInfo) { } export const save = data => { return request({ url: url + "/personnel/deptInfo/save", method: "post", data: data }); }; save(form).then(res => { }export const list = query => { return request({ url: url + "/system/tenant/department/list", method: "post", data: query }); }; tenantIdList({delFlag: 0}).then(({data: {data}}) => { this.tenantIdList = data.map(({id, name}) => ({ value: id, label: name })) });

3.@PathVariable

@PostMapping(value="/remove/{id}/{delFlag}") public Result<PersonnelDeptInfo> remove( HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id, @PathVariable("delFlag") String delFlag ) { } export const status = (id, delFlag) => { return request({ url: url + "/personnel/deptInfo/remove/" + id + "/" + delFlag, method: "post", params: {} }); }; status(row.id, delFlag).then(res => { })

特殊:@ModelAttribute

@PostMapping(value = "/getPage") public Result<IPage<PersonnelDeptInfo>> getPage( HttpServletRequest request, @RequestParam(value="pageNo", required = true) Integer pageNo, @RequestParam(value="pageSize", required = true) Integer pageSize, @ModelAttribute PersonnelDeptInfo personnelDeptInfo) { } export const list = query => { return request({ url: url + "/personnel/deptInfo/list", method: "post", data: query }); }; getPage( Object.assign( { pageNo: page.currentPage, pageSize: page.pageSize }, params, this.searchForm ) ).then(resp => { })
最新回复(0)