📄 userbean.java
字号:
package com.xmspk.ebp.comm;
/**
* @author xy
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.xmspk.ebp.database.ConnectionManager;
public class UserBean
{
//用户名
public String username;
public String loginName;
//喜欢的布局样式
public String favoriteStyle;
//部门编号
public String deptID;
//部门名称
public String dept;
//职位
public String post;
//用户描述
public String userDesc;
//用户组号
public String grpID;
//用户编号
public String userID;
public String usr_staff_id;
public UserBean()
{
}
//查询用户,供普通查询使用
public UserBean(String username)
{
Connection conn = null;
String sql = "select usr_id,usr_desc, dep_id,usr_name,grp_id, usr_pass,usr_staff_id from sys_users where usr_logname= ?";
if (!((username == null) || username.equals("")))
{
try
{
conn = ConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
ResultSet rs = stmt.executeQuery();
if (rs.next())
{
userID = rs.getString("usr_id");
userDesc = rs.getString("usr_desc");
deptID = rs.getString("dep_id");
loginName = username;
this.username = rs.getString("usr_name");
grpID = rs.getString("grp_id");
usr_staff_id = rs.getString("usr_staff_id");
stmt = conn.prepareStatement("select dep_name from sys_dept where dep_id = ?");
stmt.setString(1, deptID);
rs = stmt.executeQuery();
if (rs.next())
dept = rs.getString(1);
}
conn.close();
}
catch (SQLException ee)
{
System.out.print("User类错误:" + ee.toString());
}
}
}
public String getDeptID()
{
return deptID;
}
public String getUserName()
{
return username;
}
public String getGrpID()
{
return grpID;
}
public String getFavoriteStyle()
{
return favoriteStyle;
}
public String getUserID()
{
return userID;
}
public String getStaffID()
{
return usr_staff_id;
}
//产生用户对象实例,传入参数为用户名和密码.供HttpSession调用使用
public static UserBean Instance(String username, String password) throws Exception
{
Connection conn = null;
String sql = "select usr_id, usr_desc, dep_id,usr_name,grp_id, usr_pass,usr_staff_id from sys_users where usr_logname= ?";
UserBean user = null;
if (!((username == null) || (password == null) || username.equals("") || password.equals("")))
{
try
{
conn = ConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
ResultSet rs = stmt.executeQuery();
if (rs.next())
{
if (rs.getString("usr_pass").equals(password))
{
user = new UserBean();
user.userID = rs.getString("usr_id");
user.deptID = rs.getString("dep_id");
user.loginName = username;
user.username = rs.getString("usr_name");
user.grpID = rs.getString("grp_id");
user.usr_staff_id = rs.getString("usr_staff_id");
user.userDesc = rs.getString("usr_desc");
stmt = conn.prepareStatement("select dep_name from sys_dept where dep_id = ?");
stmt.setString(1, user.deptID);
rs = stmt.executeQuery();
if (rs.next())
user.dept = rs.getString(1);
}
}
stmt.close();
rs.close();
conn.close();
}
catch (SQLException ee)
{
System.out.print("User类错误:" + ee.toString());
throw ee;
}
}
return user;
}
public static void main(String[] arg)
{
/* Connection conn = ConnectionManager.getConnection();
Statement stmt = conn.createStatement();
stmt.setString(1, username);
ResultSet rs = stmt.executeQuery("SELECT * FROM SYS_USERS");
while (rs.next())
{
System.out.println(rs.getString("usr_logname") + "===" + rs.getString("usr_pass"));
}
*/
try
{
System.out.println(UserBean.Instance("xy", "xy").userDesc);
}
catch (Exception ee)
{
System.out.println(ee.toString());
}
}
/**
* Returns the dept.
* @return String
*/
public String getDept()
{
return dept;
}
/**
* Returns the loginName.
* @return String
*/
public String getLoginName()
{
return loginName;
}
/**
* Returns the post.
* @return String
*/
public String getPost()
{
return post;
}
/**
* Returns the userDesc.
* @return String
*/
public String getUserDesc()
{
return userDesc;
}
/**
* Returns the username.
* @return String
*/
public String getUsername()
{
return username;
}
/**
* Returns the usr_staff_id.
* @return String
*/
public String getUsr_staff_id()
{
return usr_staff_id;
}
/**
* Sets the dept.
* @param dept The dept to set
*/
public void setDept(String dept)
{
this.dept = dept;
}
/**
* Sets the deptID.
* @param deptID The deptID to set
*/
public void setDeptID(String deptID)
{
this.deptID = deptID;
}
/**
* Sets the favoriteStyle.
* @param favoriteStyle The favoriteStyle to set
*/
public void setFavoriteStyle(String favoriteStyle)
{
this.favoriteStyle = favoriteStyle;
}
/**
* Sets the grpID.
* @param grpID The grpID to set
*/
public void setGrpID(String grpID)
{
this.grpID = grpID;
}
/**
* Sets the loginName.
* @param loginName The loginName to set
*/
public void setLoginName(String loginName)
{
this.loginName = loginName;
}
/**
* Sets the post.
* @param post The post to set
*/
public void setPost(String post)
{
this.post = post;
}
/**
* Sets the userDesc.
* @param userDesc The userDesc to set
*/
public void setUserDesc(String userDesc)
{
this.userDesc = userDesc;
}
/**
* Sets the userID.
* @param userID The userID to set
*/
public void setUserID(String userID)
{
this.userID = userID;
}
/**
* Sets the username.
* @param username The username to set
*/
public void setUsername(String username)
{
this.username = username;
}
/**
* Sets the usr_staff_id.
* @param usr_staff_id The usr_staff_id to set
*/
public void setUsr_staff_id(String usr_staff_id)
{
this.usr_staff_id = usr_staff_id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -