font-size: 20px;
}
</style>
<%–头部信息–%>
<%
User user =(User)session.getAttribute(“user”);
if(user == null){
response.sendRedirect(“login.jsp”);
}else {
%>
欢迎您:<%=user.getName()%> | 安全退出 |
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding(“UTF-8”);
//获取admin.jsp页面的bookid
Integer bookid=Integer.parseInt(request.getParameter("bookid"));
//引入数据交互层
BookDao dao=new BookDaoImpl();
Book book=new Book();
book = dao.getBook(bookid);
System.out.println("删除的图书信息:");
System.out.println(book);
boolean flag=dao.deleteBook(bookid);
if(flag){
response.sendRedirect("admin.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
#### admin\_detail.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/24
Time: 10:51
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8” %>
<%@ page import=“com.sjsq.po.Book” %>
<%@ page import=“com.sjsq.po.User” %>
<%
// 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
String path = request.getContextPath();
String basePath = request.getScheme() + “😕/” + request.getServerName() + “:”
+ request.getServerPort() + path + “/”;
%>
欢迎您:<%=user.getName()%> | 安全退出 |
图书详情
图书编号 | 图书名称 | 图书价格 | 图书作者 | 图书封皮 | 图书出版社 |
<%=book.getBookid()%> | <%=book.getBookname()%> | <%=book.getPrice()%> | <%=book.getAuthor()%> | <%=book.getPicture()%> | <%=book.getPublish()%> |
#### admin\_do\_addbook.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/21
Time: 23:45
To change this template use File | Settings | File Templates.
–%>
<%@page import=“com.sjsq.dao.impl.UserDaoImpl”%>
<%@page import=“com.sjsq.dao.UserDao”%>
<%@page import=“com.sjsq.po.User”%>
<%@ page import=“com.sjsq.po.Book” %>
<%@ page import=“com.sjsq.dao.BookDao” %>
<%@ page import=“com.sjsq.dao.impl.BookDaoImpl” %>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8”%>
欢迎您:<%=user.getName()%> | 安全退出 |
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding(“UTF-8”);
Book book=new Book();
//获取admin_addbook.jsp页面提交的账号和密码
String bookname=request.getParameter(“bookname”);
Double price= Double.parseDouble(request.getParameter(“price”));
String author=request.getParameter(“author”);
String publish=request.getParameter(“publish”);
//获取admin\_addbook.jsp页面提交的账号和密码设置到实体类User中
book.setBookname(bookname);
book.setPrice(price);
book.setAuthor(author);
book.setPublish(publish);
System.out.println("添加的图书信息");
System.out.println(book);
//引入数据交互层
BookDao dao=new BookDaoImpl();
boolean flag=dao.addBook(book);
if(flag){
response.sendRedirect("admin.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
#### admin\_do\_info.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/24
Time: 10:51
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8” %>
<%@ page import=“com.sjsq.po.Book” %>
<%@ page import=“com.sjsq.service.BookService” %>
<%@ page import=“com.sjsq.service.impl.BookServiceImpl” %>
<%
// 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
String path = request.getContextPath();
String basePath = request.getScheme() + “😕/” + request.getServerName() + “:”
+ request.getServerPort() + path + “/”;
%>
#### admin\_do\_updatebook.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/21
Time: 23:45
To change this template use File | Settings | File Templates.
–%>
<%@page import=“com.sjsq.dao.impl.UserDaoImpl”%>
<%@page import=“com.sjsq.dao.UserDao”%>
<%@page import=“com.sjsq.po.User”%>
<%@ page import=“com.sjsq.po.Book” %>
<%@ page import=“com.sjsq.dao.BookDao” %>
<%@ page import=“com.sjsq.dao.impl.BookDaoImpl” %>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8”%>
<%–头部信息–%>
<%
User user =(User)session.getAttribute(“user”);
if(user == null){
response.sendRedirect(“login.jsp”);
}else {
%>
欢迎您:<%=user.getName()%> | 安全退出 |
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding(“UTF-8”);
//获取admin\_addbook.jsp页面提交的账号和密码
Integer bookid=Integer.parseInt(request.getParameter("bookid"));
String bookname = request.getParameter("bookname");
Double price = Double.parseDouble(request.getParameter("price"));
String author=request.getParameter("author");
String publish=request.getParameter("publish");
//引入数据交互层
BookDao dao=new BookDaoImpl();
Book book=new Book();
book = dao.getBook(bookid);
book.setBookname(bookname);
book.setPrice(price);
book.setAuthor(author);
book.setPublish(publish);
System.out.println("修改的图书信息");
System.out.println(book);
boolean flag=dao.updateBook(book);
if(flag){
response.sendRedirect("admin.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
#### admin\_update.jsp
<%@ page import=“com.sjsq.po.Book” %>
<%@ page import=“com.sjsq.dao.impl.BookDaoImpl” %>
<%@ page import=“com.sjsq.dao.BookDao” %>
<%@ page import=“com.sjsq.po.User” %><%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/21
Time: 23:14
To change this template use File | Settings | File Templates.
–%>
<%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8” %>
<%–头部信息–%>
<%
User user =(User)session.getAttribute(“user”);
if(user == null){
response.sendRedirect(“login.jsp”);
}
%>
修改图书
<% //获取admin.jsp页面的bookid Integer bookid=Integer.parseInt(request.getParameter("bookid")); BookDao dao=new BookDaoImpl(); Book book=new Book(); book = dao.getBook(bookid); %>
<div>
<tr>
<button type="submit" onclick="return checkForm()">修改</button>
<button type="reset">重置</button>
</tr>
</div>
#### error.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/6/10
Time: 22:28
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” %>
#### login.jsp
<%–
Created by IntelliJ IDEA.
User: shuijianshiqing
Date: 2020/5/19
Time: 22:44
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8” %>
<%
// 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
String path = request.getContextPath();
String basePath = request.getScheme() + “😕/” + request.getServerName() + “:”
+ request.getServerPort() + path + “/”;
%>
用户登录
---正在美化中---
账号: | ||
密码: | 找回密码 | |
注册 |
### 2.后端
#### User
package com.sjsq.po;
import java.io.Serializable;
/**
* @author shuijianshiqing
* @date 2020/5/19 22:19
* 用户的实体类
*/
public class User implements Serializable {
// 增加序列号,作用是反序列化的时候不会报错,切能进行IO的持久化
public static final long serialVersionUID = 1L;
private Integer id;
private String name;
private String password;
private String email;
private String phone;
private Integer isadmin;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
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 Integer getIsadmin() {
return isadmin;
}
public void setIsadmin(Integer isadmin) {
this.isadmin = isadmin;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", password='" + password + '\'' +
", email='" + email + '\'' +
", phone='" + phone + '\'' +
", isadmin=" + isadmin +
'}';
}
}
#### UserDaoImpl
package com.sjsq.dao.impl;
import com.sjsq.dao.UserDao;
import com.sjsq.po.User;
import com.sjsq.utils.BaseDao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* @author shuijianshiqing
* @date 2020/5/20 22:15
* 实现UserDao接口
*/
public class UserDaoImpl implements UserDao {
/\*\*
* 用户登录
* @param user
* @return
*/
@Override
public User login(User user) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.获取数据库连接
con = BaseDao.getConnection();
// 2.写sql
String sql = “select * from user where name = ? and password = ?”;
// 3.预编译
ps = con.prepareStatement(sql);
// 4.设置值
ps.setObject(1,user.getName());
ps.setObject(2,user.getPassword());
rs = ps.executeQuery();
User users = null;
if(rs.next()){
users = new User();
// 从数据库中获取值到实体类的setter方法中
users.setId(rs.getInt(“id”));
users.setName(rs.getString(“name”));
users.setPassword(rs.getString(“password”));
users.setEmail(rs.getString(“email”));
users.setPhone(rs.getString(“phone”));
users.setIsadmin(rs.getInt(“isadmin”));
// 返回的是你查询出来的完整的对象
return users;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
// 关闭资源,避免出现异常
BaseDao.close(con,ps,rs);
}
return null;
}
/\*\*
* 用户注册
* @param user
* @return
*/
@Override
public boolean register(User user) {
String sql = “insert into user values (0,?,?,?,?,0)”;
List list = new ArrayList();
list.add(user.getName());
list.add(user.getPassword());
list.add(user.getEmail());
list.add(user.getPhone());
boolean flag = BaseDao.addUpdateDelete(sql,list.toArray());
if(flag){
return true;
}else {
return false;
}
}
/\*\*
* 查询用户信息
* @param sql
* @param arr
* @return
*/
@Override
public List selectUser(String sql, Object[] arr) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = BaseDao.getConnection();
// 2.预编译
ps = con.prepareStatement(sql);
if(arr != null){
for (int i = 0; i < arr.length; i++) {
ps.setObject(i+1,arr[i]);
}
}
// 3.执行sql
rs = ps.executeQuery();
// 4.保存查询出来的数据到list
List<User> list = new ArrayList<User>();
while(rs.next()){
User user = new User();
// 从数据库中获取值到实体类的setter方法中
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setEmail(rs.getString("email"));
user.setPhone(rs.getString("phone"));
user.setIsadmin(rs.getInt("isadmin"));
// 测试数据
System.out.println("Dao层测试日志,显示用户信息:");
System.out.println(user);
// 将对象保存到list中
list.add(user);
}
return list;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
// 关闭资源,避免出现异常
BaseDao.close(con,ps,rs);
}
return null;
}
}
#### BookDao
package com.sjsq.dao;
import com.sjsq.po.Book;
import java.util.List;
/**
* @author shuijianshiqing
* @date 2020/5/20 23:13
* 图书信息接口
*/
public interface BookDao {
/\*\*
* 查询图书信息
* @param sql
* @param arr
* @return
*/
public List select(String sql,Object[] arr);
/\*\*
* 根据图书编号进行查询
* @param id
* @return
*/
public Book getBook(Integer id);
/\*\*
* 图书新增
* @param book
* @return
*/
public boolean addBook(Book book);
/\*\*
* 图书修改
* @param book
* @return
*/
public boolean updateBook(Book book);
/\*\*
* 删除图书
* @param bookid
* @return
*/
public boolean deleteBook(Integer bookid);
}
#### BookDaoImpl
package com.sjsq.dao.impl;
import com.sjsq.dao.BookDao;
import com.sjsq.po.Book;
import com.sjsq.utils.BaseDao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* @author shuijianshiqing
* @date 2020/5/20 23:15
*/
public class BookDaoImpl implements BookDao {
@Override
public List<Book> select(String sql, Object[] arr) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = BaseDao.getConnection();
// 2.预编译
ps = con.prepareStatement(sql);
if(arr != null){
for (int i = 0; i < arr.length; i++) {
// 传入sql的参数
ps.setObject(i+1,arr[i]);
}
}
// 3.执行sql
rs = ps.executeQuery();
// 4.保存查询出来的数据到list
List<Book> list = new ArrayList<Book>();
while (rs.next()){
Book book = new Book();
book.setBookid(rs.getInt("bookid"));
总结
总体来说,如果你想转行从事程序员的工作,Java开发一定可以作为你的第一选择。但是不管你选择什么编程语言,提升自己的硬件实力才是拿高薪的唯一手段。
如果你以这份学习路线来学习,你会有一个比较系统化的知识网络,也不至于把知识学习得很零散。我个人是完全不建议刚开始就看《Java编程思想》、《Java核心技术》这些书籍,看完你肯定会放弃学习。建议可以看一些视频来学习,当自己能上手再买这些书看又是非常有收获的事了。
, Object[] arr) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = BaseDao.getConnection();
// 2.预编译
ps = con.prepareStatement(sql);
if(arr != null){
for (int i = 0; i < arr.length; i++) {
// 传入sql的参数
ps.setObject(i+1,arr[i]);
}
}
// 3.执行sql
rs = ps.executeQuery();
// 4.保存查询出来的数据到list
List list = new ArrayList();
while (rs.next()){
Book book = new Book();
book.setBookid(rs.getInt(“bookid”));
总结
总体来说,如果你想转行从事程序员的工作,Java开发一定可以作为你的第一选择。但是不管你选择什么编程语言,提升自己的硬件实力才是拿高薪的唯一手段。
如果你以这份学习路线来学习,你会有一个比较系统化的知识网络,也不至于把知识学习得很零散。我个人是完全不建议刚开始就看《Java编程思想》、《Java核心技术》这些书籍,看完你肯定会放弃学习。建议可以看一些视频来学习,当自己能上手再买这些书看又是非常有收获的事了。
[外链图片转存中…(img-1gyAKj6t-1719258126446)]