总结
三个工作日收到了offer,头条面试体验还是很棒的,这次的头条面试好像每面技术都问了我算法,然后就是中间件、MySQL、Redis、Kafka、网络等等。
- 第一个是算法
关于算法,我觉得最好的是刷题,作死的刷的,多做多练习,加上自己的理解,还是比较容易拿下的。
而且,我貌似是将《算法刷题LeetCode中文版》、《算法的乐趣》大概都过了一遍,尤其是这本
《算法刷题LeetCode中文版》总共有15个章节:编程技巧、线性表、字符串、栈和队列、树、排序、查找、暴力枚举法、广度优先搜索、深度优先搜索、分治法、贪心法、动态规划、图、细节实现题
《算法的乐趣》共有23个章节:
- 第二个是Redis、MySQL、kafka(给大家看下我都有哪些复习笔记)
基本上都是面试真题解析、笔记和学习大纲图,感觉复习也就需要这些吧(个人意见)
- 第三个是网络(给大家看一本我之前得到的《JAVA核心知识整理》包括30个章节分类,这本283页的JAVA核心知识整理还是很不错的,一次性总结了30个分享的大知识点)
Servlet下
登录LoginServlet
查找SearchServlet
删除DeleteServlet
修改ChangeServlet
添加addServlet
Service下
FileServic接口下
FileServiceImpl实现类下
pojo下
User学生类
Dao下
FileDao接口下
FileDaoImpl实现类下
utils下
JDBCUtils
实现流程和思路
========
创建jsp页面,然后转发到servlet下,接受jsp页面传过来的值,拿着这些值去访问service服务层接口,服务层写个实类,这个实现类去服务层的接口,然后这个服务层的实现类再去访问dao层的接口,在持久层dao中在编写一个dao层接口的实现类去实现dao层的接口,最后在dao层的的实现类去访问数据库。
图示:
项目视频演示
=======
学生管理系统项目演示
设置数据库studenttest
================
①、创建user表
其中包括设置删除的u_isdelete(0是存在,1是删除)
create table user(
u_name varchar(20),
u_id int primary key auto_increment,
u_pwd varchar(20) ,
u_phone varchar(20) not null,
u_role int not null,
u_isdelete int not null
)
charset=utf8;
创建项目
====
项目界面总览
jsp页面
=====
登录界面login.jsp
<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8” %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + “😕/” + request.getServerName() + “:” + request.getServerPort() + path + “/”;
%>
<%-- css代码–%>
登录界面
用户:
${error}
密码:
重置
登录
主界面mainPage.jsp
<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8” %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + “😕/” + request.getServerName() + “:” + request.getServerPort() + path + “/”;
%>
<%–JSTL语法,可以使用user.getName()方法–%>
<%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
名字:${user.getU_name()}
编号:${user.getU_id()}
<button style=“font-size: 18px; height: 28px;” id="cx"margin-left: 30px>查询
<button style=“font-size: 18px; height: 28px;” id=“addUser” margin-left: 100px>添加
删除
修改
${tip}
<%–jstl语法遍历,var是一个指指针–%>
<c:forEach items=“${arr}” var=“item”>
${item.getU_id()} ${item.getU_name()} ${item.getU_phone()} 优秀 良好</c:forEach>
添加学生信息AddUser.jsp
<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8” %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + “😕/” + request.getServerName() + “:” + request.getServerPort() + path + “/”;
%>
<%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
添加学生信息
密码:
电话号码:
提交
修改学生信息change.jsp
<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8” %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + “😕/” + request.getServerName() + “:” + request.getServerPort() + path + “/”;
%>
修改学生信息
修改的学生id:
姓名:
密码:
电话号码:
提交
Servlet下
========
登录LoginServlet
package com.StudentTest.Servlet;
import com.StudentTest.pojo.User;
import com.StudentTest.service.FileService;
import com.StudentTest.service.FileServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet(“/login”)
public class LoginServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String u_id=null,u_pwd=null;
User u = new User();
try{//非数字异常判断
u_id = req.getParameter(“u_id”);
u_pwd = req.getParameter(“u_pwd”);
u.setU_id(Integer.valueOf(u_id));
u.setU_pwd(u_pwd);
}catch (Exception e){
req.setAttribute(“error”, “你输入的不是数字”);
//错误就回到主界面
req.getRequestDispatcher(“login.jsp”).forward(req, resp);
}
//实现登录服务层的业务逻辑层,从服务层service到持久层dao
FileService fs=new FileServiceImpl();
//返回user这样可以看到登录的用户是谁
/**
-
如果user为空说明账号密码不一致,跳转到登录界面
-
不为空说明账号密码一致,跳转到主界面
*/
User user = null;
try {
user = fs.loginService(u);
} catch (Exception e) {
e.printStackTrace();
}
if (user != null) {
fs=new FileServiceImpl();
//查看所有数据
ArrayList arrUser=fs.getAllStudent();
//将这些数据转发到前端
req.setAttribute(“arr”,arrUser);
req.setAttribute(“user”, user);
//跳转到主界面
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
} else {
req.setAttribute(“error”, “密码不匹配”);
req.getRequestDispatcher(“login.jsp”).forward(req, resp);
}
}
}
查找SearchServlet
package com.StudentTest.Servlet;
import com.StudentTest.pojo.User;
import com.StudentTest.service.FileService;
import com.StudentTest.service.FileServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet(“/searchServlet”)
public class SearchServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置字符集为
req.setCharacterEncoding(“UTF-8”);
String v=req.getParameter(“v”);
//访问service层,在由service访问dao层
FileService fs=new FileServiceImpl();
//创建service方法到dao层中去访问
User u=fs.searchIdName(v);
//创建集合用来接受dao层访问后的数据
ArrayList arr=new ArrayList<>();
//将数据添加到集合中去
arr.add(u);
//获取登录人员的信息
String id=req.getParameter(“id”);
//创建service服务层,通过service访问doa层
FileService fs2=new FileServiceImpl();
//通过一连串的访问,最终去访问
User admine=fs2.getAdmint(id);
//将登录的信息发送到前端
req.setAttribute(“user”, admine);
//如果访问的信息不为空
if(u!=null){
//管理员信息
req.setAttribute(“arr”,arr);
//跳转到主界面
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}else{
FileService f=new FileServiceImpl();
ArrayList arr2=f.getAllStudent();
req.setAttribute(“arr”, arr2);
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}
}
}
删除DeleteServlet
package com.StudentTest.Servlet;
import com.StudentTest.pojo.User;
import com.StudentTest.service.FileService;
import com.StudentTest.service.FileServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet(“/deleteServlet”)
public class DeleteServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding(“UTF-8”);
String del=req.getParameter(“v”);
//获取登录人信息
String adm=req.getParameter(“id”);
//访问service层,在service层创建对应的方法
FileService fs=new FileServiceImpl();
ArrayList list=fs.getAllStudent();
//获取登录人员信息
User u = fs.getAdmint(adm);
//service层调用方法,转到dao层执行sql语句
boolean user=fs.delUser(del);
String tip=“”;
if(user){
tip=“删除成功”;
}else {
tip=“删除失败”;
}
//发送到前端
req.setAttribute(“user”, u);
req.setAttribute(“arr”, list);
req.setAttribute(“tip”, tip);
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}
}
修改ChangeServlet
package com.StudentTest.Servlet;
import com.StudentTest.pojo.User;
import com.StudentTest.service.FileService;
import com.StudentTest.service.FileServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet(“/changeUser”)
public class ChangeServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding(“UTF-8”);
String id=req.getParameter(“u_id”);
String pwd=req.getParameter(“u_pwd”);
String phone=req.getParameter(“u_phone”);
String name=req.getParameter(“u_name”);
FileService fs=new FileServiceImpl();
User user=new User(name,Integer.valueOf(id),pwd,phone);
String adm=req.getParameter(“id”);
//获取登录人员信息
User u = fs.getAdmint(adm);
System.out.println(u);
boolean flag=fs.changeUser( user);
ArrayList list=fs.getAllStudent();
String tip=“”;
if (flag){
tip=“修改成功”;
}else{
tip=“修改失败”;
}
//发送到前端
req.setAttribute(“tip”,tip);
req.setAttribute(“user”, u);
req.setAttribute(“arr”, list);
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}
}
添加addServlet
package com.StudentTest.Servlet;
import com.StudentTest.pojo.User;
import com.StudentTest.service.FileService;
import com.StudentTest.service.FileServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet(“/addUser”)
public class AddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding(“UTF-8”);
String id=req.getParameter(“u_id”);
String pwd=req.getParameter(“u_pwd”);
String phone=req.getParameter(“u_phone”);
String name=req.getParameter(“u_name”);
FileService fs=new FileServiceImpl();
User user=new User(name,Integer.valueOf(id),pwd,phone);
String adm=req.getParameter(“id”);
//获取登录人员信息
User u = fs.getAdmint(adm);
System.out.println(u);
boolean flag=fs.addUser( user);
ArrayList list=fs.getAllStudent();
String tip=“”;
if (flag){
tip=“添加成功”;
}else{
tip=“添加失败”;
}
//发送到前端
req.setAttribute(“tip”,tip);
req.setAttribute(“user”, u);
req.setAttribute(“arr”, list);
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}
}
Service下
========
FileServic接口下
package com.StudentTest.service;
import com.StudentTest.pojo.User;
import java.util.ArrayList;
public interface FileService {
ArrayList getAllStudent();
User searchIdName(String v);
User getAdmint(String id);
boolean delUser(String del);
boolean addUser(User user);
boolean changeUser(User user);
User loginService(User u) throws Exception;
}
FileServiceImpl实现类下
package com.StudentTest.service;
import com.StudentTest.Dao.FileDao;
import com.StudentTest.Dao.FileDaoImpl;
import com.StudentTest.pojo.User;
import java.util.ArrayList;
总结
在这里,由于面试中MySQL问的比较多,因此也就在此以MySQL为例为大家总结分享。但是你要学习的往往不止这一点,还有一些主流框架的使用,Spring源码的学习,Mybatis源码的学习等等都是需要掌握的,我也把这些知识点都整理起来了
ystem.out.println(u);
boolean flag=fs.addUser( user);
ArrayList list=fs.getAllStudent();
String tip=“”;
if (flag){
tip=“添加成功”;
}else{
tip=“添加失败”;
}
//发送到前端
req.setAttribute(“tip”,tip);
req.setAttribute(“user”, u);
req.setAttribute(“arr”, list);
req.getRequestDispatcher(“mainPage.jsp”).forward(req, resp);
}
}
Service下
========
FileServic接口下
package com.StudentTest.service;
import com.StudentTest.pojo.User;
import java.util.ArrayList;
public interface FileService {
ArrayList getAllStudent();
User searchIdName(String v);
User getAdmint(String id);
boolean delUser(String del);
boolean addUser(User user);
boolean changeUser(User user);
User loginService(User u) throws Exception;
}
FileServiceImpl实现类下
package com.StudentTest.service;
import com.StudentTest.Dao.FileDao;
import com.StudentTest.Dao.FileDaoImpl;
import com.StudentTest.pojo.User;
import java.util.ArrayList;
总结
在这里,由于面试中MySQL问的比较多,因此也就在此以MySQL为例为大家总结分享。但是你要学习的往往不止这一点,还有一些主流框架的使用,Spring源码的学习,Mybatis源码的学习等等都是需要掌握的,我也把这些知识点都整理起来了
[外链图片转存中…(img-luSt6mbV-1715059368360)]
[外链图片转存中…(img-2HO6ZYIq-1715059368360)]