1.在页面中使用sec:authentication="name"获取用户的姓名
<a href="javascript:;" sec:authentiaction="name">姓名</a>
2.使用springsecurity后不能在controller中使用session取用户,只能通过一下代码来获取用户信息。
@RequestMapping("/index")
public String index(Model model) {
//读取当前登录成功用户的角色,并根据角色加载菜单
//获得spring security用户
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext()
.getAuthentication()
.getPrincipal();
//读取当前用户管理的菜单
List<SysMenu> menuList = sysMenuService.findListByName(userDetails.getUsername());
//获取当前登录的系统用户
model.addAttribute("menus", menuList);
return "sys/index";
}