一、项目介绍
本系统由读者端和管理员端,读者端主要有主要有三大功能,借阅图书、归还图书和查看自己的借阅信息,管理员端主要有四个大的功能,对图书进行管理,对用户进行管理、对借阅信息进行管理、对图书分类进行管理。
整体功能模块图,如图所示:
- 借还图书:读者对图书进行借阅与归还
- 查看借阅信息:读者对自己借阅信息的查看,可以根据借阅信息归还图书
- 图书管理:管理员对图书的管理,可以对图书进行增删改查。
- 图书分类管理:管理员对图书类别的管理,可以对图书类别进行增删改查。
- 借阅信息管理:管理员对所有读者用户的借阅信息可以进行查看,并且可以帮助读者点击归还。
- 读者管理:管理员对所有读者用户进行管理,可以对读者信息进行增删改查。
二、项目技术栈
- 后端:javaweb+jdk+tomcat8+mvc
- 前端:jsp+css+js
- 数据库:mysql
三、核心代码
用户实体类
public class AdminBean {
public AdminBean() {
super();
// TODO Auto-generated constructor stub
}
private int aid;//用户管理员id
private int status;//用来判断是管理员还是读者,读者的值为1,管理员为2
private String username;//账号,
private String name;//读者的姓名
private String password;//密码
private String email;//邮箱
private String phone;//手机号
private int lend_num;//可借阅天数
private int max_num;//最大可借数
public int getAid() {
return aid;
}
public void setAid(int aid) {
this.aid = aid;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public int getLend_num() {
return lend_num;
}
public void setLend_num(int lend_num) {
this.lend_num = lend_num;
}
public int getMax_num() {
return max_num;
}
public void setMax_num(int max_num) {
this.max_num = max_num;
}
}
用户登录
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
AdminDao userdao = new AdminDao();
AdminDao admindao = new AdminDao();
/**
* @see HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//登录的判断
//编码格式
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
//获取账号和密码
// PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username);
//对账号和密码进行判断
boolean result = userdao.Login_verify(username, password);
System.out.println(result);
HttpSession session = request.getSession();
//判断输入正确
if(result){
AdminBean adminbean = new AdminBean();
//更加账号和密码查找出读者的信息
adminbean = admindao.getAdminInfo(username,password);
//将aid存入session中
session.setAttribute("aid", ""+adminbean.getAid());
//设置session的失效时间
session.setMaxInactiveInterval(6000);
//根据status的值来判断是管理员,还是读者,status=1为读者
System.out.println(adminbean.getStatus());
if(adminbean.getStatus()==1){
response.sendRedirect("index2.jsp");
}else{
response.sendRedirect("admin.jsp");
}
}else{
//没有找到对应的账号和密码,返回重新登录
session.setAttribute("state", "密码错误");
response.sendRedirect("login.jsp");
}
}
}
数据库连接配置
public class DbUtil {
public static String username = "root";
public static String pwd = "abc123456";
public static String url = "jdbc:mysql://localhost:3307/books?serverTimezone=UTC";
static{
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
public static Connection getConn(){
Connection conn = null;
try{
conn = DriverManager.getConnection(url,username,pwd);
} catch (SQLException e){
e.printStackTrace();
}
return conn;
}
public static void CloseDB(ResultSet rs, PreparedStatement stm, Connection conn){
if(rs!=null)
{
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stm!=null)
{
try {
stm.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null)
{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
注册操作
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public RegisterServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
//获取注册信息
AdminDao userdao = new AdminDao();
String username = request.getParameter("username");
String password = request.getParameter("password");
String name = request.getParameter("name");
String email = request.getParameter("email");
String phone = request.getParameter("phone");
System.out.println(username);
//默认设置最大借阅数和借阅天数
int lend_num = 30;
int max_num = 5;
//将注册信息存入数据库,再返回登录
userdao.Register(username,password,name,email,phone,lend_num,max_num);
response.sendRedirect("login.jsp");
}
}
四、项目展示
系统主框架
图书管理主页面
增加图书页面
修改图书页面
读者管理主页面
添加读者页面
图书分类管理主页面
图书借阅信息管理主页面
帮助读者归还图书页面
读者借阅图书页面
五、源代码
打包为压缩包了,后台私我发给你!
标签:username,课程设计,Java,String,request,num,源码,public,图书 From: https://blog.csdn.net/2401_84040513/article/details/137272314