Good morning, I am currently developing a rest api with Spring Boot :: (v1.5.9.RELEASE) to control the management of a table called File, which persists with other entities,
The controller to call the service is as follows:
@RestController
public class ExpedientController {
@Autowired
protected ExpedientService expedientService;
@Autowired
protected ExpedientSubserviceService expedientSubserviceService;
protected UserService userService;
protected ObjectMapper mapper;
@CrossOrigin(origins = "*")
@RequestMapping(value = "/api/expedient/saveOrUpdate",method = RequestMethod.POST)
public RestResponse saveOrUpdate(@RequestBody String expedientJSON) throws JsonParseException, JsonMappingException, IOException {
this.mapper= new ObjectMapper();
Expedient expedient=this.mapper.readValue(expedientJSON,Expedient.class);
this.expedientService.save(expedient);
String message = Integer.toString(expedient.getId())+" "+Integer.toString(expedient.assured.getId());
return new RestResponse(HttpStatus.OK.value(), message);
}
@CrossOrigin(origins = "*")
@RequestMapping(value = "/api/expedient/getAll", method = RequestMethod.GET)
public List<Expedient> getAll() {
return this.expedientService.findAllByDeletedAt(0);
}
@RequestMapping(value = "/api/expedient/delete", method = RequestMethod.POST)
public void deleteExpedient(@RequestBody String expedientJson) throws Exception {
this.mapper = new ObjectMapper();
Expedient expedient = this.mapper.readValue(expedientJson, Expedient.class);
if (expedient.getId()==0) {
throw new Exception("El id esta nulo");
}
this.expedientService.delete(expedient.getId());
}
The Json of the query is large due to the number of objects that persist between them. Is it recommended that separate queries be made without the need to bring all the information of the persisted entities in the json? Or is there some compression method that can be used.
Hello, it depends a lot on the architecture of the service and how it would be consumed, but you can do several things:
Example Pagination:
I hope it has been helpful for you
Greetings.