Values of @PathVariable and @ModelAttribute overlapping

后端 未结 2 1686
北海茫月
北海茫月 2021-01-11 18:03

I have an User object stored in the session with @SessionAttributes. And a straight-forward method decorated with @ModelAttribute in o

相关标签:
2条回答
  • 2021-01-11 18:48

    use @SessionAttribute

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
        public String showItem(@PathVariable("id") Long id, @SessionAttribute("user") User user,
                Model uiModel) {
       ...    
    }
    
    0 讨论(0)
  • 2021-01-11 18:52

    How about this approach -

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String showItem(@PathVariable("id") Long id,
                Model uiModel) {
           User user = (User)uiModel.asMap().get("user");
       ...    
    }
    
    0 讨论(0)
提交回复
热议问题