从session中获取用户的信息有(用户id,用户名称;用户部门id,用户部门名称;用户机构id,用户机构名称)。
在具体写代码过程中,我们会从已创建好的session类中去获取,如下:
IUser user = LoginCtrlSession.getLoginVO();
定义一个user对象,后面需要获取用户的信息的话,则直接使用如:user.getYhId();具体的session类!!!
public class LoginCtrlSession {
public LoginCtrlSession() {
//构造函数
}
//具体的getLoginVO方法
public static IUser getLoginVO(ServletRequest... request) {
IUser loginVO = null;
Object object = null;
HttpServletRequest req;
if (request.length > 0 && request[0] != null) {
req = (HttpServletRequest)request[0];
object = req.getSession().getAttribute("login_user");
} else {
req = (HttpServletRequest)ThreadPool.get("request");
if (req != null) {
object = req.getSession().getAttribute("login_user");
}
}
if (object != null) {
loginVO = (IUser)object;
}
return loginVO;
}
}
(一)获取用户id,用户名称;
//用户id
public static String getYhid() {
String yhid = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
yhid = loginVO.getYhId();
}
return yhid;
}
//用户名称
public static String getYhDm() {
String yhdm = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
yhdm = loginVO.getYhDm();
}
return yhdm;
}
(二)获取用户部门id,部门名称;
//用户部门id
public static String getBmid() {
String bmid = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
bmid = loginVO.getBmid();
}
return bmid;
}
//用户部门名称
public static String getBmmc() {
String bmmc = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
bmmc = loginVO.getBmmc();
}
return bmmc;
}
(三)获取用户机构id,机构名称;
//用户机构id
public static String getUnitname() {
String jgmc = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
jgmc = loginVO.getUnitname();
}
return jgmc;
}
//用户机构名称
public static String getUnitcode() {
String unitcode = "";
IUser loginVO = getLoginVO();
if (loginVO != null) {
unitcode = loginVO.getUnitcode();
}
return unitcode;
}