登录后如何获取用户数据,请帮忙
@RequestMapping(值="/登录"( 公共字符串登录(@RequestParam(值 = "错误",必需 = 假( 字符串错误, @RequestParam(值 = "注销",必需 = 假(字符串注销,模型模型( { 身份验证 = SecurityContextHolder.getContext((.getAuthentication(( ; 字符串名称 = auth.getName(( ; User us = user.findByUsername(name( ; 字符串错误消息 = 空;
if(error != null) {
errorMessge = "Username ou Password est incorrect !";
}
if(logout != null) {
errorMessge = "hello" ;
System.out.println(name) ;
model.addAttribute("prenom", us.getNom());
}
model.addAttribute("errorMessge", errorMessge);
model.addAttribute("prenom",name) ;
return "admin.jsp" ;
}
在我的主页上显示名称,如下所示:
@ModelAttribute
public void info(Model model) {
UserPrincipal aut = (UserPrincipal)SecurityContextHolder.getContext().getAuthentication().getPrincipal() ;
String name = aut.getUsername();
User us = user.findByUsername(name) ;
model.addAttribute("prenom",us.getPrenom()) ;
}
@RequestMapping(值="/登录",方法 = RequestMethod.POST( 公共字符串登录(@RequestParam(值 = "错误",必需 = 假( 字符串错误, @RequestParam(值 = "注销", 必需 = 假(字符串注销,模型模型( {
String errorMessge = null;
if(error != null) {
errorMessge = "Username ou Password est incorrect !";
}
if(logout != null) {
errorMessge = "hello" ;
// model.addAttribute("prenom", us.getNom());
}
// model.addAttribute("prenom", us.getNom());
model.addAttribute("errorMessge", errorMessge);
model.addAttribute("prenom",name( ;
return "admin.jsp" ;
}