/**
* @项目名称: UOLMyBatis
* @文件名称: UserDao.java
* @Date: 2019年7月23日
* @Copyright: 2019 www.xxx.com Inc. All rights reserved.
* 注意:本内容仅限于xxx公司内部传阅,禁止外泄以及用于其他的商业目的
*/
package com.ychs.uol.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import com.ychs.uol.mapper.UserMapper;
import com.ychs.uol.model.User;
import com.ychs.uol.util.DBUtil;
import com.ychs.uol.util.MyMD5Util;
/**
* UserDao类
*
* @author: liuhao
* @version 1.0
*/
public class UserDao {
/**
* 登陆验证
*
* @param userName 用户名
* @param userPwd 用户密码
* @return 登陆成更返回true,失败返回false
*/
public boolean checkUser(String userName, String userPwd) {
boolean result = false;
SqlSession sqlSession = DBUtil.getSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
User user = userMapper.checkUser(userName, userPwd);
if (user != null) {
result = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return result;
}
/**
* 添加用户
*
* @param user 封装的用户对象
* @return 添加成功返回1,失败返回0
*/
public int inserUser(User user) {
int result = 0;
SqlSession sqlSession = null;
try {
/** 获取工厂 */
sqlSession = DBUtil.getSession();
// 获取UserMapper映射接口
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
// 对密码进行加密
String userPwd = user.getUserPwd();
user.setUserPwd(MyMD5Util.getEncryptedPwd(userPwd));
// 调用接口中的方法
result = userMapper.insertUser(user);
// 提交事务commit
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放资源
sqlSession.close();
}
return result;
}
/**
* 删除用户
*
* @param userId 用户ID
* @return 删除成功返回1,失败返回0
*/
public int deleteUser(String userId) {
int result = 0;
SqlSession sqlSession = DBUtil.getSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
result = userMapper.deleteUser(userId);
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return result;
}
/**
* 根据用户ID查询用户
*
* @param userId 用户ID
* @return 查询到的User对象
*/
public User selectUserById(String userId) {
User user = null;
SqlSession sqlSession = null;
try {
sqlSession = DBUtil.getSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
user = userMapper.selectUserById(userId);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return user;
}
/**
* 根据用户名查询用户
*
* @param userName 用户名
* @return 查询到的User对象
*/
public User selectUserByName(String userName) {
User user = null;
SqlSession sqlSession = null;
try {
sqlSession = DBUtil.getSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
user = userMapper.selectUserByName(userName);
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return user;
}
/**
* 查询所有用户
*
* @return 查询到的用户集合
*/
public List<User> selectAllUser() {
List<User> userList = new ArrayList<User>();
SqlSession sqlSession = DBUtil.getSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
userList = userMapper.selectAllUser();
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return userList;
}
/**
* 修改用户
*
* @param user 修改后的用户对象
* @return 修改成功返回1, 失败返回0
*/
public int modifyUser(User user) {
int result = 0;
SqlSession sqlSession = DBUtil.getSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
result = userMapper.modifyUser(user);
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return result;
}
/**
* 禁用户用
*
* @param userId 用户ID
* @return 禁用成功返回1, 失败返回0
*/
public int banUser(String userId) {
int result = 0;
SqlSession sqlSession = DBUtil.getSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
result = userMapper.banUser(userId);
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return result;
}
/**
* 查询用户并分页显示 方式一:使用MyBatis
*
* @param currPage 当前页码(从1开始)
* @param pageSize 每页的记录个数
* @return 查询到的用户集合
*/
public List<User> selectUserPage(int currPage, int pageSize) {
List<User> userList = new ArrayList<User>();
SqlSession sqlSession = DBUtil.getSession();
// 偏移量,当前页第一条记录的序号(从0开始)
int offset = (currPage - 1) * pageSize;
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
userList = userMapper.selectUserPage(new RowBounds(offset, pageSize));
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return userList;
}
/**
* 查询用户并分页显示 方式二:自己写SQL
*
* @param currPage 当前页码(从1开始)
* @param pageSize 每页的记录个数
* @return 查询到的用户集合
*/
public List<User> selectUserPageSql(int currPage, int pageSize) {
List<User> userList = new ArrayList<User>();
SqlSession sqlSession = DBUtil.getSession();
// 当前页第一条记录的序号(从1开始)
int begin = (currPage - 1) * pageSize + 1;
// 当前页最后一条记录的序号
int end = begin + (pageSize - 1);
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
userList = userMapper.selectUserPageSql(begin, end);
sqlSession.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeSession(sqlSession);
}
return userList;
}
/**
* 主键自增
*
* @param user 用户对象
* @return 添加成功返回1,失败返回0
*/
public int insertUserKeyAutoInc(User user) {
int result = 0;
SqlSession sqlSession = DBUtil.getSession();
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计基于JavaWeb的联合开放实验室管理系统源代码+数据库 使用说明 一、登陆 登陆网址:http://http://localhost:8080/J1012Web/main.jsp 用户名:xiaocao密码:xiaocao 用户名:lala密码:123 二、SQL文件 包含内容: 表结构及其数据 视图 序列 执行方式 第一步:打开数据库客户端链接上数据库 第二步:右键点击数据库表,选择导入数据,选择提供的sql文件进行导入 三、服务器部署项目 找到war包 找到电脑安装的tomcat目录 将war包直接放入webapps下 找到bin目录下的startup.bat批处理文件,双击启动tomcat 打开浏览器访问项目 找到bin目录下的shutdown.bat批处理文件,双击关闭tomcat 四、未完成的功能 Echarts与数据库的结合使用 实验室成员以及公开课成员的分页
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计基于JavaWeb的联合开放实验室管理系统源代码+数据库+使用说明 (595个子文件)
bootstrap.min.css 137KB
style.css 19KB
stylesheet.css 13KB
tinymce.css 9KB
default.css 9KB
laydate.css 8KB
select.css 2KB
editor.css 605B
iconfont.eot 2KB
tinymce.gif 12KB
default.gif 7KB
etc_24.gif 1KB
etc_33.gif 1KB
etc_32.gif 1KB
etc_36.gif 1KB
etc_31.gif 1KB
etc_30.gif 1KB
etc_25.gif 1KB
etc_26.gif 1012B
etc_34.gif 992B
etc_35.gif 989B
etc_27.gif 978B
etc_02.gif 687B
etc_12.gif 687B
etc_16.gif 685B
etc_15.gif 683B
etc_03.gif 682B
etc_08.gif 680B
etc_01.gif 671B
etc_09.gif 670B
etc_13.gif 666B
etc_06.gif 660B
etc_07.gif 657B
etc_14.gif 657B
etc_10.gif 657B
etc_04.gif 655B
etc_11.gif 655B
etc_05.gif 643B
etc_22.gif 473B
etc_20.gif 453B
etc_18.gif 453B
etc_17.gif 445B
etc_23.gif 444B
etc_19.gif 423B
topbg.gif 415B
etc_29.gif 342B
etc_21.gif 322B
etc_28.gif 303B
lefttop.gif 204B
tcbg.gif 203B
toolbg.gif 133B
righttop.gif 82B
inputbg.gif 82B
leftmenubg.gif 76B
th.gif 76B
list.gif 70B
pre.gif 70B
list1.gif 70B
next.gif 70B
div.gif 64B
px.gif 61B
ol.gif 60B
ul.gif 60B
dl.gif 59B
rlist.gif 56B
p.gif 54B
line.gif 51B
leftline.gif 50B
PIE.htc 40KB
index-14.html 56KB
LabMember.html 31KB
UserServiceImpl.html 29KB
User.html 29KB
index-7.html 26KB
UserDao.html 23KB
UserMapper.html 22KB
overview-tree.html 22KB
UserService.html 20KB
OpenCourse.html 20KB
index-4.html 19KB
User.html 19KB
LabMember.html 19KB
index-15.html 19KB
CourseMember.html 19KB
index-1.html 17KB
UserDaoTest.html 17KB
index-3.html 16KB
LabMemberServiceImpl.html 16KB
Major.html 15KB
serialized-form.html 15KB
Department.html 14KB
WrapperRequest.html 14KB
School.html 14KB
CourseMember.html 14KB
MajorServiceImpl.html 14KB
index-8.html 13KB
SchoolServiceImpl.html 13KB
OpenCourse.html 13KB
Department.html 13KB
index-10.html 13KB
共 595 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
程序员柳
- 粉丝: 6091
- 资源: 1185
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功