java – 如何为使用Spring Cache缓存的Spring Web Service设置正
发布时间:2020-12-15 05:03:10 所属栏目:Java 来源:网络整理
导读:我有这样的 Spring MVC控制器: @Controller@RequestMapping(value = "/user")public class UserController { ..... @Cacheable(value = "users",key = "#id") @RequestMapping(value = "/get",method = RequestMethod.GET) @ResponseBody public User getUs
我有这样的
Spring MVC控制器:
@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); } .... } 我想将标题Last-Modified添加到GetUser Web服务的HTTP响应中. 解决方法
这个怎么样:
@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); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |