securityContext 获取变量
securityContext getVariables
登录后如何获取用户数据,请帮忙
@RequestMapping(value="/login")
public String login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false)String logout,Model 模型) {
身份验证 auth = SecurityContextHolder.getContext().getAuthentication() ;
字符串名称 = auth.getName() ;
用户 us = user.findByUsername(name) ;
字符串 errorMessge = null;
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" ;
}
*** 在我的主页上显示这样的名称:
${prenom}
Deconnexion
@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(value="/login", method = RequestMethod.POST)
public String login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false)String logout,Model 模型) {
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",姓名);
return "admin.jsp" ;
}
登录后如何获取用户数据,请帮忙
@RequestMapping(value="/login") public String login(@RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false)String logout,Model 模型) { 身份验证 auth = SecurityContextHolder.getContext().getAuthentication() ; 字符串名称 = auth.getName() ; 用户 us = user.findByUsername(name) ; 字符串 errorMessge = null;
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(value="/login", method = RequestMethod.POST) public String login(@RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false)String logout,Model 模型) {
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",姓名);
return "admin.jsp" ;
}