美文网首页
Spring mvc 获得当前用户

Spring mvc 获得当前用户

作者: 湛青 | 来源:发表于2017-01-21 12:34 被阅读44次

在 controller 的 action 参数中加上 @AuthenticationPrincipal User user即可!

        @RequestMapping(value = {"/new", "/{id}"}, method = RequestMethod.GET)
            public String form(
                    Model model,
                    @PathVariable(required = false) Integer id,
                    @AuthenticationPrincipal User user
            ) {
        }

记得将 User 改成你 UserDetailsService 中所返回的 Class

相关文章

网友评论

      本文标题:Spring mvc 获得当前用户

      本文链接:https://www.haomeiwen.com/subject/ooogbttx.html