admin 管理员组

文章数量: 1086019


2024年1月13日发(作者:selfstacking)

@RestController@RequestMapping("/dept")public class DeptController { @Autowired private DeptService deptService; /** *

分页查询 * @param page * @param size * @param keywords * @return */ @GetMapping("/") public RespPageBean findAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, String keywords){ age(page, size); List list = lDept(keywords); PageInfo pageInfo = new PageInfo(list); RespPageBean bean = new RespPageBean(); a(t()); al(al()); return bean; } /** *

删除 * @param deptno * @return */ @DeleteMapping("/{deptno}") public RespBean deleteDept(@PathVariable Integer deptno){ if(ById(deptno)==1){ return _SUCCESS;//删除成功 } return _ERROR;//删除失败 } /** *

添加 * @param dept * @return */ @PostMapping("/") public RespBean addDept(@RequestBody Dept dept){ if(t(dept)==1){ return _SUCCESS;//添加成功 } return _ERROR;//添加失败 } /** *

更新 * @param dept * @return */ @PutMapping("/") public RespBean updateDept(@RequestBody Dept dept){ if(DeptById(dept)==1){ return _SUCCESS;//添加成功 } return _ERROR;//添加失败 }9. 还有两个帮助类

public class RespBean { private Integer status; private String msg; private Object obj; public RespBean(Integer status, String msg) { = status; = msg; } public static final RespBean DELETE_SUCCESS = new RespBean(200,"删除成功"); public static final RespBean DELETE_ERROR = new RespBean(-1,"删除失败"); public static final RespBean ADD_SUCCESS = new RespBean(200,"添加成功"); public static final RespBean ADD_ERROR = new RespBean(-1,"添加失败"); public static final RespBean UPDATE_SUCCESS = new RespBean(200,"更新成功"); public static final RespBean UPDATE_ERROR = new RespBean(-1,"更新失败"); public Integer getStatus() { return status; } public void setStatus(Integer status) { = status; } public String getMsg() { return msg; } public void setMsg(String msg) { = msg; } public Object getObj() { return obj; } public void setObj(Object obj) { = obj; } private RespBean(Integer status, String msg, Object obj) { = status; = msg; = obj; } private RespBean() { }}

3.添加封装 get,put,post,delete请求import axios from 'axios'import {Message} from 'element-ui';//结果拦截(success => { //

是后端RespBean中响应的信息 if ( && == -1 && == 500) { ({message: }) return; } //

是后端RespBean中响应的信息 if () { s({message: }) } return ;}, error => { //

是后端RespBean中响应的信息 if () { ({message: }) } else { ({message: '未知错误!'}) } return;})/** * post请求 * @param url

请求地址 * @param params

请求参数 * @returns {AxiosPromise} */export const postRequest=(url,params)=>{ return axios({ method:'post', url:`${url}`, data:params })}/** * get请求 * @param url

请求地址 * @param params

请求参数 * @returns {AxiosPromise} */export const getRequest=(url,params)=>{ return axios({ method:'get', url:`${url}`, data:params })}/** * put请求 * @param url

请求地址 * @param params

请求参数 * @returns {AxiosPromise} */export const putRequest=(url,params)=>{ return axios({ method:'put', url:`${url}`, data:params })}/** * delete请求 * @param url

请求地址 * @param params

请求参数


本文标签: 失败 请求 添加 还有