美好的一天,我目前正在使用 Spring Boot :: (v1.5.9.RELEASE) 开发一个 rest api 来控制一个名为 File 的表的处理,该表与其他实体一起存在,
调用服务的控制器如下:
@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());
}
查询的Json由于它们之间持久化的对象数量很大,是否建议单独查询,而不需要将持久化实体的所有信息带入json中?或者是否有一些可以使用的压缩方法。
您好,这在很大程度上取决于服务的架构以及如何使用它,但是您可以做几件事:
示例分页:
我希望它对你有帮助
问候。