/** * "/list/{start}/{length}" */ public static final String LIST = "/list/{start}/{length}"; /** * "/page/{number}/{length}" */ public static final String PAGE = "/page/{number}/{length}"; /** * "/detail/{id}" */ public static final String DETAIL = "/detail/{id}"; /** * "/create" */ public static final String CREATE = "/create"; /** * "/create/batch" */ public static final String CREATE_BATCH = "/create/batch"; /** * "/update" */ public static final String UPDATE = "/update"; /** * "/update/batch" */ public static final String UPDATE_BATCH = "/update/batch"; /** * "/remove/{id}" */ public static final String REMOVE = "/remove/{id}"; /** * "/remove/batch" */ public static final String REMOVE_BATCH = "/remove/batch"; /** * "/post/page" */ public static final String POST_PAGE = "/post/page"; /** * "/post/detail" */ public static final String POST_DETAIL = "/post/detail"; /** * "/post/update" */ public static final String POST_UPDATE = "/post/update"; /** * "/post/remove" */ public static final String POST_REMOVE = "/post/remove";对java的接口路径做统一的axiosch处理和调用处理
时间: 2024-04-06 21:35:11 浏览: 22
对于Java的接口路径,我们可以使用axios库来进行统一的处理和调用处理。我们可以先在前端定义一个统一的接口调用方法:
```
import axios from 'axios';
const api = axios.create({
baseURL: 'http://your-java-backend.com',
});
export function fetchList(start, length) {
return api.get(`/list/${start}/${length}`);
}
export function fetchPage(number, length) {
return api.get(`/page/${number}/${length}`);
}
export function fetchDetail(id) {
return api.get(`/detail/${id}`);
}
export function create(data) {
return api.post('/create', data);
}
export function createBatch(data) {
return api.post('/create/batch', data);
}
export function update(data) {
return api.put('/update', data);
}
export function updateBatch(data) {
return api.put('/update/batch', data);
}
export function remove(id) {
return api.delete(`/remove/${id}`);
}
export function removeBatch(data) {
return api.delete('/remove/batch', { data });
}
export function postPage(data) {
return api.post('/post/page', data);
}
export function postDetail(data) {
return api.post('/post/detail', data);
}
export function postUpdate(data) {
return api.post('/post/update', data);
}
export function postRemove(data) {
return api.post('/post/remove', data);
}
```
在使用时,只需要调用相应的方法即可:
```
import { fetchList } from './api';
fetchList(0, 10).then(response => {
console.log(response.data);
}).catch(error => {
console.error(error);
});
```
这样,我们就可以对Java的接口路径做统一的axios处理和调用处理了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)