Java – Etag support for versioned entities
•
Java
I intend to support etag.com for my restfull spring application Most of the resources I expose are versioned in dB
I know shallowetag headerfilter, which is not what I need, because it can only save bandwidth
Is there a production ready solution for spring MVC that associates the Etag header with the exposed entity version?
Solution
Spring data rest supports this out of the box function. See the conditional request part of the reference documentation
You can also use spring framework 4.2 0, which supports the conditional request of responseentity type returned by the controller method – see reference documentation
It's like:
@RequestMapping("/book/{id}") public ResponseEntity<Book> showBook(@PathVariable Long id) { Book book = findBook(id); String version = book.getVersion(); return ResponseEntity .ok() .cacheControl(CacheControl.maxAge(30,TimeUnit.DAYS)) .eTag(version) // lastModified is also available .body(book); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码