如何在spring mvc和hibernate中检索登录的用户数据 [英] How to retrive logged in user data in spring mvc and hibernate

查看:122
本文介绍了如何在spring mvc和hibernate中检索登录的用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获得当前登录用户的详细信息,包括娱乐session.Is有任何潜在的做到 Spring hibernate

我是spring和hibernate的新手......帮助我们。

解决方案

有很多方法可以完成这个任务。在控制器中,你可以注入一个 Pricipal 作为参数。

  @ RequestMapping()
public void getPricipal(Principal principal){
Customer c =(Customer)pricipal;
}

您应该也可以注入 UserDetails 。春天会为你解决它。您的 Customer 类必须实现UserDetails

  @RequestMapping()
public void getPricipal(Customer customer){

}






至于所有的细节,如果你已经实现你自己的 UserDetailsS​​ervice ,你应该能够访问名字,姓氏等您的自定义 UserDetails 客户)。


I need to get current loggedin user's details along entertain session.Is there any poissible to do it in Spring and hibernate

I am new to spring and hibernate...Help me guys.

解决方案

There are serveral ways in which you can accomplish this. In a controller you can inject a Pricipal as a parameter.

@RequestMapping()
public void getPricipal(Principal principal) {
   Customer c = (Customer) pricipal;
}

You should also be able to inject the UserDetails directly as well. Spring will resolve it for you. Your Customer class must implement UserDetails

@RequestMapping()
public void getPricipal(Customer customer) {

}


As for having all details, you should be able to access the firstname, lastname etc, if you've implemented your own UserDetailsService where you return your custom UserDetails (Customer).

这篇关于如何在spring mvc和hibernate中检索登录的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆