Java – how to set the correct last modified header value for spring Web Services cached using spring cache?
•
Java
I have a spring MVC controller:
@Controller
@RequestMapping(value = "/user")
public class UserController {
.....
@Cacheable(value = "users",key = "#id")
@RequestMapping(value = "/get",method = RequestMethod.GET)
@ResponseBody
public User getUser(Long id){
return userService.get(id);
}
....
}
I want to add the title last modified to the HTTP response of getuser web service How do I get the correct date when adding a cache in my store? How do I add the last modified title of this date to the response of the spring controller method?
Solution
How's this?
@Controller
@RequestMapping(value = "/user")
class UserController {
@Cacheable(value = "users",key = "#id")
@RequestMapping(value = "/get",method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<User> getUser(Long id) {
HttpHeaders headers = new HttpHeaders();
headers.set("Last-Modified",dateFormat.format(new Date()));
return new ResponseEntity<SecurityProperties.User>(headers,userService.get(id),HttpStatus.OK);
}
}
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
二维码
