Below is my way to change just one data
@RequestMapping(value = "/updateroomstatus", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public Response<SaveResponse> updateRoomStatus(@RequestBody Request<RoomDetail> request, HttpServletRequest httpServletRequest) throws ParseException, JsonProcessingException {
Response<SaveResponse> rvalue = new Response<>();
Status status = new Status();
String user = request.getSession().getUserId();
log.info("Headers : " + HttpUtil.getHeadersInfo(httpServletRequest).toString());
log.info("Incoming request from " + httpServletRequest.getRemoteAddr() + ":" + httpServletRequest.getRemotePort() + "\n"
+ " Method : " + httpServletRequest.getMethod() + "\n"
+ " TLS : " + httpServletRequest.isSecure() + "\n"
+ " Path : " + httpServletRequest.getRequestURI() + "\n"
+ " Body : " + mapper.writeValueAsString(request));
RoomDetail updatedData = request.getPayload();
Optional<RoomDetail> getData = roomDetailRepository.findById(updatedData.getId());
if(getData.isPresent()) {
RoomDetail oldData = getData.get();
//just one data can update
oldData.setStatus(updatedData.getStatus());
oldData.setDescription(updatedData.getDescription());
roomDetailRepository.saveAndFlush(oldData);
status.setStatusCode("000");
status.setStatusDesc("Success");
} else {
status.setStatusCode("001");
status.setStatusDesc("Data Not Found");
}
log.info("Resp : " + status.toString());
rvalue.setStatus(status);
return rvalue;
}
When making a request using Postman, it will be like this. And this works well
{
"id": 91,
"description": "normal",
"status": "Occupied"
}
What I want is to do a bulk update, which is changing a lot of data. And it looks like this
[
{
"id": 91,
"description": "Very Good",
"status": "Occupied"
},
{
"id": 93,
"description": "Normal",
"status": "Vacant Dirty"
},
{
"id": 98,
"description": "Not bad",
"status": "Occupie Dirty"
}
]
I got information that doing bulk updates is by adding arrays and looping. Can anyone help?