Spring dynamic HttpStatus from a variable

Viewed 4933

I have an application where I am returning dynamic HttpStatus code from my controller by using ResponseEntity

return new ResponseEntity<String>("Unrecognised request.", HttpStatus.BAD_REQUEST);

The next requirement is that the response body and the status code will be loaded from database. and the code will looking something like

String msg = <<loaded from database>>;
String status = <<loaded from database>>; //type can be changed to int
return new ResponseEntity<String>(msg, <..what to do here ??..>);

Not the status code will be retrived from database as a string/integer. And as HttpStatus is an Enum, I didn't find any other way to do that.

Is there any solution to my requirement?

1 Answers
Related