logindao.java
来自「用JAVA环境开发的人力资源管理系统」· Java 代码 · 共 38 行
JAVA
38 行
package com.liyu.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.liyu.beans.UserInfo;
public class LoginDao extends JdbcDaoSupport{
private static final String GET_USERINFO_SQL = "SELECT USER_NAME,USER_PASSWORD,USER_ROLE "
+ "FROM USER_INFO WHERE USER_NAME=? AND USER_PASSWORD=?";
public UserInfo getUserInfo(String userName,String userPassword) {
return (UserInfo) this.getJdbcTemplate().query(GET_USERINFO_SQL, new Object[] {userName,userPassword}, new InfoptExtractor());
}
private static class InfoptExtractor implements ResultSetExtractor {
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
if (!rs.next()) {
return null;
}
UserInfo userInfo = new UserInfo();
userInfo.setUserName((StringUtils.defaultString(rs.getString("USER_NAME"))));
userInfo.setUserPassword((StringUtils.defaultString(rs.getString("USER_PASSWORD"))));
userInfo.setUserRole((StringUtils.defaultString(rs.getString("USER_ROLE"))));
return userInfo;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?