我的解決方案基于前端應(yīng)用程序 React、redux 和 material-u 以及后端 Springboot 應(yīng)用程序。我有一個 Rest API,可以從數(shù)據(jù)庫中獲取大量記錄。這會在 UI 上造成延遲,我想防止這種情況發(fā)生。表格組件:export default function Export(props) { return ( <div> <MaterialTable title={<Typography variant="h6">{}</Typography>} data={props.data} options={{ pageSize: 50, pageSizeOptions: [50, 100, 150], search: true, sorting: false, headerStyle: { fontWeight: "bold", padding: "4px", }, }} ></MaterialTable></div> );}export const getExportByLastModifiedDate = (lastModifiedDate) => { return async (dispatch) => { dispatch({ type: EXPORT_BY_LASTMODIFEDDATE_START }); await axios({ method: "get", url: "/api/export?lastModifiedDate=" + lastModifiedDate, }) .then(function(response) { dispatch({ type: EXPORT_BY_LASTMODIFEDDATE_SUCCESS, payload: response.data, }); }) .catch(function(error) { dispatch({ type: EXPORT_BY_LASTMODIFEDDATE_ERROR, payload: error }); }); };};后端API:@GetMapping("/export")public ResponseEntity<List<ExportDto>> getExportByLastModifiedDate(@RequestParam(value = "lastModifiedDate", required = true) String lastModifiedDate) { Optional<List<ExportDto>> optional = Optional.ofNullable(service.getExportByLastModifiedDate(lastModifiedDate)); return optional.map(response -> ResponseEntity.ok().body(response)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));}我想要做的是獲取前 1000 條記錄并將它們呈現(xiàn)給 UI,而在后端過程將繼續(xù)。我怎樣才能做到這一點 ?
使用 Spring Boot 響應(yīng)延遲加載數(shù)據(jù)
紫衣仙女
2023-04-27 17:18:12