1、背景提出

2、实践目的

3、技术要点

4、技术分工

5、时间分配

6、编写后台代码

(1)管理员登录

(2)快递管理

(3)快递员管理

(4)用户管理

(5)数据库

(6)过滤器

(7)实体类

7、目录

8、微信端实现

9、过程梳理

10、前台实现

11、新知识引入——layer

12、新知识引入——内网穿透

13、发送短信及验证码

14、运行效果


1、背景提出


随着互联网和通信技术的高速发展,使电子商务迅速普及,网购成为人们购物的重要手段之一。据统计2019年双十一,11月11日~16日,受电商平台集中促销影响,业务量达全年高峰,6天内共处理邮(快)件23.09亿件。

疫情期间配送快递成了一件难事。疫情防控已经趋于常态化,很多小区出台了新的治安管理条例,开始禁止快递人员进入。这给民众收发快件造成了极大的不便,因进不去小区,快递人员只能在小区门口周边摆摊设点,也影响了小区周边环境。

除了快递,外卖也一样面临相同的问题。除了小区,写字楼、校园也面临着相同的问题。正是基于对疫情期间配送最后一公里深刻的认识,我们探索出一条解决之道,那就是社区快递e栈(类似快递柜)。

2、实践目的

1、锻炼动手能力

2、融会贯通JavaWeb技术

3、体验项目开发流程

4、做出上线级别的微信端+JavaWeb后端项目

5、为框架阶段打下前后端交互的基础

3、技术要点


html5、css3、js、Jquery、bootstrap、layui、layer、ajax、mysql、tomcat、servlet、filter、listener、jsp、公有云服务器。

4、技术分工

后台必做功能:

1.管理员登录

2.管理员退出

3.快件增加

4.快件删除

5.快件修改

6.快件列表查看

7.用户增加

8.用户删除

9.用户删除

10.用户列表查看

11.快递员增加

12.快递员删除

13.快递员修改

14.快递员查询

选做:

1.控制台-显示快件区域区分图

2.控制台-显示用户人数

3.控制台-显示快递员人数

4.控制台-显示总快件数

5.控制台-显示等待取件数量

前台必做功能:

1.用户/快递员登录

2.用户/快递员注册

3.用户-我的取件列表(未取件/已取件)

4.用户-快件取件码展示

5.快递员-扫码取件

6.快递员-取件码取件

7.首页根据快递单号查询快递信息

选做:

1.快递员-录入快递

2.快递员历史查询

3.个人中心-昵称显示与修改

4.懒人排行榜

5.自动登录

6.修改密码

5、时间分配

3、12开始,……

3、18结束

6、编写后台代码

(1)管理员登录

Controller

@ResponseBody("/admin/login.do")
    public String login(HttpServletRequest request, HttpServletResponse response){
        //1.    接参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //2.    调用Service传参数,并获取结果
        boolean result = AdminService.login(username, password);
        //3.    根据结果,准备不同的返回数据
        Message msg = null;
        if(result){
            msg = new Message(0,"登录成功");//{status:0,result:"登录成功"}
            //登录时间 和 ip的更新
            Date date = new Date();
            String ip = request.getRemoteAddr();
            AdminService.updateLoginTimeAndIP(username,date,ip);
            request.getSession().setAttribute("adminUserName","username");
        }else{
            msg = new Message(-1,"登录失败");//{status:-1,result:"登录失败"}
        }
        //4.    将数据转换为JSON
        String json = JSONUtil.toJSON(msg);
        //5.    将JSON回复给ajax
        return json;
    }

Service

public static boolean login(String username,String password){
        return dao.login(username,password);
    }
}

(2)快递管理

快递的列表

- 分页查询的列表

@ResponseBody("/express/list.do")
    public String list(HttpServletRequest request, HttpServletResponse response){
        //1.    获取查询数据的起始索引值
        int offset = Integer.parseInt(request.getParameter("offset"));
        //2.    获取当前页要查询的数据量
        int pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
        //3.    进行查询
        List<Express> list = ExpressService.findAll(true, offset, pageNumber);
        List<BootStrapTableExpress> list2 = new ArrayList<>();
        for(Express e:list){
            String inTime = DateFormatUtil.format(e.getInTime());
            String outTime = e.getOutTime()==null?"未出库":DateFormatUtil.format(e.getOutTime());
            String status = e.getStatus()==0?"待取件":"已取件";
            String code = e.getCode()==null?"已取件":e.getCode();
            BootStrapTableExpress e2 = new BootStrapTableExpress(e.getId(),e.getNumber(),e.getUsername(),e.getUserPhone(),e.getCompany(),code,inTime,outTime,status,e.getSysPhone());
            list2.add(e2);
        }
        List<Map<String, Integer>> console = ExpressService.console();
        Integer total = console.get(0).get("data1_size");
        //4.    将集合封装为 bootstrap-table识别的格式
        ResultData<BootStrapTableExpress> data = new ResultData<>();
        data.setRows(list2);
        data.setTotal(total);
        String json = JSONUtil.toJSON(data);
        return json;
    }

新增快递

@ResponseBody("/express/insert.do")
    public String insert(HttpServletRequest request, HttpServletResponse response){
        String number = request.getParameter("number");
        String company = request.getParameter("company");
        String username = request.getParameter("username");
        String userPhone = request.getParameter("userPhone");
        //Express e = new Express(number,company,username,userPhone, UserUtil.getUserPhone(request.getSession()));
        Express e = new Express(number,username,userPhone,company,UserUtil.getUserPhone(request.getSession()));
        boolean flag = ExpressService.insert(e);
        Message msg = new Message();
        if(flag){
            //录入成功
            msg.setStatus(0);
            msg.setResult("快递录入成功!");
        }else{
            //录入失败
            msg.setStatus(-1);
            msg.setResult("快递录入失败!");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 用户输入内容,后台接收参数,向数据库存储

删除快递

@ResponseBody("/express/delete.do")
    public String delete(HttpServletRequest request,HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        boolean flag = ExpressService.delete(id);
        Message msg = new Message();
        if(flag){
            msg.setStatus(0);
            msg.setResult("删除成功");
        }else{
            msg.setStatus(-1);
            msg.setResult("删除失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }
}

- 用户输入快递单号查询到快递信息
- 浏览快递信息的最后,可以点击删除按钮 ,删除快递

修改快递

@ResponseBody("/express/find.do")
    public String find(HttpServletRequest request,HttpServletResponse response){
        String number = request.getParameter("number");
        Express e = ExpressService.findByNumber(number);
        Message msg = new Message();
        if(e == null){
            msg.setStatus(-1);
            msg.setResult("单号不存在");
        }else{
            msg.setStatus(0);
            msg.setResult("查询成功");
            msg.setData(e);
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

    /**
     * 更新
     * @param request
     * @param response
     * @return
     */
    @ResponseBody("/express/update.do")
    public String update(HttpServletRequest request,HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        String number = request.getParameter("number");
        String company = request.getParameter("company");
        String username = request.getParameter("username");
        String userPhone = request.getParameter("userPhone");
        int status = Integer.parseInt(request.getParameter("status"));
        Express newExpress = new Express();
        newExpress.setNumber(number);
        newExpress.setCompany(company);
        newExpress.setUsername(username);
        newExpress.setUserPhone(userPhone);
        newExpress.setStatus(status);
        boolean flag = ExpressService.update(id, newExpress);
        Message msg = new Message();
        if(flag){
            msg.setStatus(0);
            msg.setResult("修改成功");
        }else{
            msg.setStatus(-1);
            msg.setResult("修改失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 用户输入快递单号查询到快递信息
- 浏览(可修改)快递信息的最后,可以点击确认按钮 ,确认修改快递

(3)快递员管理

快递员的列表

- 分页查询的列表

@ResponseBody("/courier/list.do")
    public String list(HttpServletRequest request, HttpServletResponse response){
        int offset = Integer.parseInt(request.getParameter("offset"));
        // 获取当前页要查询的数据量
        int pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
        List<Courier> list = CourierService.findAll(true, offset, pageNumber);
        List<BootStrapTableCourier> list2 = new ArrayList<>();
        for (Courier c : list){
            String enrollTime = DateFormatUtil.format(c.getEnrollTime());
            String loginTime = c.getLoginTime()==null?"未登录":DateFormatUtil.format(c.getLoginTime());
            String sendNumber = null;
            int courierSendNumber = c.getCourierSendNumber();
            if (courierSendNumber <= 10000){
                sendNumber = courierSendNumber + "";
            }else{
                sendNumber = courierSendNumber/10000 + "w+";
            }
            BootStrapTableCourier c2 = new BootStrapTableCourier(c.getId(),c.getCourierName(),c.getCourierPhone(),"******",c.getCourierPassword(),sendNumber,enrollTime,loginTime);
            list2.add(c2);
        }
        List<Map<String, Integer>> console = CourierService.console();
        Integer total = console.get(0).get("data_size");
        ResultData<BootStrapTableCourier> data = new ResultData<>();
        data.setRows(list2);
        data.setTotal(total);
        String json = JSONUtil.toJSON(data);
        return json;
    }

新增快递员

@ResponseBody("/courier/insert.do")
    public String insert(HttpServletRequest request, HttpServletResponse response){
        String courierName = request.getParameter("courierName");
        String courierPhone = request.getParameter("courierPhone");
        String courierIdNumber = request.getParameter("courierIdNumber");
        String courierPassword = request.getParameter("courierPassword");
        Courier c = new Courier(courierName,courierPhone,courierIdNumber,courierPassword);
        boolean flag = CourierService.insert(c);
        Message msg = new Message();
        if (flag){
            msg.setStatus(0);
            msg.setResult("快递员录入成功");
        }else {
            msg.setStatus(-1);
            msg.setResult("快递员录入失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 管理员输入内容,后台接收参数,向数据库存储

删除快递

@ResponseBody("/courier/delete.do")
    public String delete(HttpServletRequest request, HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        boolean flag = CourierService.delete(id);
        Message msg = new Message();
        if (flag){
            msg.setStatus(0);
            msg.setResult("删除成功");
        }else {
            msg.setStatus(-1);
            msg.setResult("删除失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 快递员输入快递单号查询到快递信息
- 浏览快递信息的最后,可以点击删除按钮 ,删除快递

修改快递

@ResponseBody("/courier/find.do")
    public String find(HttpServletRequest request, HttpServletResponse response){
        String courierPhone = request.getParameter("courierPhone");
        Courier c = CourierService.findByPhone(courierPhone);
        Message msg = new Message();

        if (c == null){
            msg.setStatus(-1);
            msg.setResult("手机号不存在");
        }else {
            msg.setStatus(0);
            msg.setResult("查询成功");
            msg.setData(c);
        }

        String json = JSONUtil.toJSON(msg);
        return json;
    }

    @ResponseBody("/courier/update.do")
    public String update(HttpServletRequest request, HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        String courierName = request.getParameter("courierName");
        String courierPhone = request.getParameter("courierPhone");
        String courierIdNumber = request.getParameter("courierIdNumber");
        String courierPassword = request.getParameter("courierPassword");

        Courier newCourier = new Courier(courierName,courierPhone,courierIdNumber,courierPassword);
        Message msg = new Message();
        boolean flag = CourierService.update(id, newCourier);
        if (flag){
            msg.setStatus(0);
            msg.setResult("修改成功");
        }else {
            msg.setStatus(-1);
            msg.setResult("修改失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 快递员输入快递单号查询到快递信息
- 浏览(可修改)快递信息的最后,可以点击确认按钮 ,确认修改快递

(4)用户管理

用户的列表

- 分页查询的列表

@ResponseBody("/user/list.do")
    public String list(HttpServletRequest request, HttpServletResponse response){
        //1.    获取查询数据的起始索引值
        int offset = Integer.parseInt(request.getParameter("offset"));
        //2.    获取当前页要查询的数据量
        int pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
        //3.    进行查询
        List<Express> list = ExpressService.findAll(true, offset, pageNumber);
        List<BootStrapTableExpress> list2 = new ArrayList<>();
        for(Express e:list){
            String inTime = DateFormatUtil.format(e.getInTime());
            String outTime = e.getOutTime()==null?"未出库":DateFormatUtil.format(e.getOutTime());
            String status = e.getStatus()==0?"待取件":"已取件";
            String code = e.getCode()==null?"已取件":e.getCode();
            BootStrapTableExpress e2 = new BootStrapTableExpress(e.getId(),e.getNumber(),e.getUsername(),e.getUserPhone(),e.getCompany(),code,inTime,outTime,status,e.getSysPhone());
            list2.add(e2);
        }
        List<Map<String, Integer>> console = ExpressService.console();
        Integer total = console.get(0).get("data1_size");
        //4.    将集合封装为 bootstrap-table识别的格式
        ResultData<BootStrapTableExpress> data = new ResultData<>();
        data.setRows(list2);
        data.setTotal(total);
        String json = JSONUtil.toJSON(data);
        return json;
    }

新增快递员

@ResponseBody("/user/insert.do")
    public String insert(HttpServletRequest request, HttpServletResponse response){
        String userName = request.getParameter("userName");
        String userPhone = request.getParameter("userPhone");
        String userIdNumber = request.getParameter("userIdNumber");
        String userPassword = request.getParameter("userPassword");
        User u = new User(userName, userPhone, userIdNumber, userPassword);
        boolean flag = UserService.insert(u);
        Message msg = new Message();
        if (flag){
            msg.setStatus(0);
            msg.setResult("用户录入成功");
        }else{
            msg.setStatus(-1);
            msg.setResult("用户录入失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 用户输入内容,后台接收参数,向数据库存储

删除快递员

@ResponseBody("/user/delete.do")
    public String delete(HttpServletRequest request, HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        boolean flag = UserService.delete(id);
        Message msg = new Message();
        if (flag){
            msg.setStatus(0);
            msg.setResult("删除成功");
        }else {
            msg.setStatus(-1);
            msg.setResult("删除失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 用户输入快递单号查询到快递信息
- 浏览快递信息的最后,可以点击删除按钮 ,删除快递员

修改快递员

@ResponseBody("/user/find.do")
    public String find(HttpServletRequest request, HttpServletResponse response){
        String userPhone = request.getParameter("userPhone");
        User u = UserService.findByUserPhone(userPhone);
        Message msg = new Message();
        if (u == null){
            msg.setStatus(-1);
            msg.setResult("手机号不存在");
        }else {
            msg.setStatus(0);
            msg.setResult("查询成功");
            msg.setData(u);
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

    /**
     * 删除
     * @param request
     * @param response
     * @return
     */
    @ResponseBody("/user/update.do")
    public String update(HttpServletRequest request, HttpServletResponse response){
        int id = Integer.parseInt(request.getParameter("id"));
        String userName = request.getParameter("userName");
        String userPhone = request.getParameter("userPhone");
        String userIdNumber = request.getParameter("userIdNumber");
        String userPassword = request.getParameter("userPassword");
        User newUser = new User(userName,userPhone,userIdNumber,userPassword);
        Message msg = new Message();
        boolean flag = UserService.update(id, newUser);
        if (flag){
            msg.setStatus(0);
            msg.setResult("修改成功");
        }else {
            msg.setStatus(-1);
            msg.setResult("修改失败");
        }
        String json = JSONUtil.toJSON(msg);
        return json;
    }

- 用户输入快递单号查询到快递信息
- 浏览(可修改)快递信息的最后,可以点击确认按钮 ,确认修改快递员

(5)数据库

-德鲁伊数据库操作,MYSQL5.7

#德鲁伊数据库连接
url=jdbc:mysql://localhost:3306/e?useUnicode=true&characterEncoding=utf-8
username=root
password=123
driverClassName=com.mysql.jdbc.Driver
initialSize=5
maxActive=10
minIdle=5
maxWait=3000

(6)过滤器

权限

@WebFilter({"/admin/index.html","/admin/views/*","/express/*","/courier/*","/user/*"})
public class AccessControlFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        String userName = UserUtil.getUserName(request.getSession());
        if(userName != null)
            chain.doFilter(req, resp);
        else
            response.sendError(404,"很遗憾,权限不足");
    }

    public void init(FilterConfig config) throws ServletException {

    }

字符编码

@WebFilter("*.do")
public class CharSetFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

(7)实体类

分别生成get/set方法,无参,有参及其他方法

Express(快递)

public class Express {
    private int id;
    private String number;
    private String username;
    private String userPhone;
    private String company;
    private String code;
    private Timestamp inTime;
    private Timestamp outTime;
    private int status;
    private String sysPhone;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Express express = (Express) o;
        return id == express.id &&
                status == express.status &&
                Objects.equals(number, express.number) &&
                Objects.equals(username, express.username) &&
                Objects.equals(userPhone, express.userPhone) &&
                Objects.equals(company, express.company) &&
                Objects.equals(code, express.code) &&
                Objects.equals(inTime, express.inTime) &&
                Objects.equals(outTime, express.outTime) &&
                Objects.equals(sysPhone, express.sysPhone);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, number, username, userPhone, company, code, inTime, outTime, status, sysPhone);
    }

    @Override
    public String toString() {
        return "Express{" +
                "id=" + id +
                ", number='" + number + '\'' +
                ", username='" + username + '\'' +
                ", userPhone='" + userPhone + '\'' +
                ", company='" + company + '\'' +
                ", code='" + code + '\'' +
                ", inTime=" + inTime +
                ", outTime=" + outTime +
                ", status=" + status +
                ", sysPhone='" + sysPhone + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Timestamp getInTime() {
        return inTime;
    }

    public void setInTime(Timestamp inTime) {
        this.inTime = inTime;
    }

    public Timestamp getOutTime() {
        return outTime;
    }

    public void setOutTime(Timestamp outTime) {
        this.outTime = outTime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getSysPhone() {
        return sysPhone;
    }

    public void setSysPhone(String sysPhone) {
        this.sysPhone = sysPhone;
    }

    public Express(String number, String username, String userPhone, String company, String sysPhone,String code) {
        this.number = number;
        this.username = username;
        this.userPhone = userPhone;
        this.company = company;
        this.sysPhone = sysPhone;
        this.code = code;
    }

    public Express(String number, String username, String userPhone, String company, String sysPhone) {
        this.number = number;
        this.username = username;
        this.userPhone = userPhone;
        this.company = company;
        this.sysPhone = sysPhone;
    }

    public Express() {
    }

    public Express(int id, String number, String username, String userPhone, String company, String code, Timestamp inTime, Timestamp outTime, int status, String sysPhone) {
        this.id = id;
        this.number = number;
        this.username = username;
        this.userPhone = userPhone;
        this.company = company;
        this.code = code;
        this.inTime = inTime;
        this.outTime = outTime;
        this.status = status;
        this.sysPhone = sysPhone;
    }

Courier(快递员)

public class Courier {
    private int id;
    private String courierName;
    private String courierPhone;
    private String courierIdNumber;
    private String courierPassword;
    private int courierSendNumber;
    private Timestamp enrollTime;
    private Timestamp loginTime;

    public Courier() {
    }

    public Courier(String courierName, String courierPhone, String courierIdNumber, String courierPassword) {
        this.courierName = courierName;
        this.courierPhone = courierPhone;
        this.courierIdNumber = courierIdNumber;
        this.courierPassword = courierPassword;
    }

    public Courier(int id, String courierName, String courierPhone, String courierIdNumber, String courierPassword, int courierSendNumber, Timestamp enrollTime, Timestamp loginTime) {
        this.id = id;
        this.courierName = courierName;
        this.courierPhone = courierPhone;
        this.courierIdNumber = courierIdNumber;
        this.courierPassword = courierPassword;
        this.courierSendNumber = courierSendNumber;
        this.enrollTime = enrollTime;
        this.loginTime = loginTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCourierName() {
        return courierName;
    }

    public void setCourierName(String courierName) {
        this.courierName = courierName;
    }

    public String getCourierPhone() {
        return courierPhone;
    }

    public void setCourierPhone(String courierPhone) {
        this.courierPhone = courierPhone;
    }

    public String getCourierIdNumber() {
        return courierIdNumber;
    }

    public void setCourierIdNumber(String courierIdNumber) {
        this.courierIdNumber = courierIdNumber;
    }

    public String getCourierPassword() {
        return courierPassword;
    }

    public void setCourierPassword(String courierPassword) {
        this.courierPassword = courierPassword;
    }

    public int getCourierSendNumber() {
        return courierSendNumber;
    }

    public void setCourierSendNumber(int courierSendNumber) {
        this.courierSendNumber = courierSendNumber;
    }

    public Timestamp getEnrollTime() {
        return enrollTime;
    }

    public void setEnrollTime(Timestamp enrollTime) {
        this.enrollTime = enrollTime;
    }

    public Timestamp getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Timestamp loginTime) {
        this.loginTime = loginTime;
    }

    @Override
    public String toString() {
        return "Courier{" +
                "id=" + id +
                ", courierName='" + courierName + '\'' +
                ", courierPhone='" + courierPhone + '\'' +
                ", courierIdNumber='" + courierIdNumber + '\'' +
                ", courierPassword='" + courierPassword + '\'' +
                ", courierSendNumber=" + courierSendNumber +
                ", enrollTime=" + enrollTime +
                ", loginTime=" + loginTime +
                '}';
    }

User(用户)

public class User {
    private int id;
    private String userName;
    private String userPhone;
    private String userIdNumber;
    private String userPassword;
    private Timestamp enrollTime;
    private Timestamp loginTime;
    private boolean user;

    public User() {
    }

    public User(String userName, String userPhone, String userIdNumber, String userPassword) {
        this.userName = userName;
        this.userPhone = userPhone;
        this.userIdNumber = userIdNumber;
        this.userPassword = userPassword;
    }

    public User(int id, String userName, String userPhone, String userIdNumber, String userPassword, Timestamp enrollTime, Timestamp loginTime) {
        this.id = id;
        this.userName = userName;
        this.userPhone = userPhone;
        this.userIdNumber = userIdNumber;
        this.userPassword = userPassword;
        this.enrollTime = enrollTime;
        this.loginTime = loginTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserIdNumber() {
        return userIdNumber;
    }

    public void setUserIdNumber(String userIdNumber) {
        this.userIdNumber = userIdNumber;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public Timestamp getEnrollTime() {
        return enrollTime;
    }

    public void setEnrollTime(Timestamp enrollTime) {
        this.enrollTime = enrollTime;
    }

    public Timestamp getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Timestamp loginTime) {
        this.loginTime = loginTime;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", userPhone='" + userPhone + '\'' +
                ", userIdNumber='" + userIdNumber + '\'' +
                ", userPassword='" + userPassword + '\'' +
                ", enrollTime=" + enrollTime +
                ", loginTime=" + loginTime +
                '}';
    }

7、目录

前台(主要)

后台

8、微信端实现

前台

以主页进行展示

<!DOCTYPE html>
<html>
<head>
	<title>快件e栈服务平台</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<link href="css/normalize.css" type="text/css" rel="stylesheet" />
	<link href="css/main.css" type="text/css" rel="stylesheet" />
	<script src="js/jquery.min.js" type="text/javascript"></script>
	<script src="js/notice.js"  type="text/javascript"></script>
	<script src="js/common.js" type="text/javascript"></script>
	<script src="layer/layer.js"></script>
</head>
<body>
	<div class="content">
		<div class="top autoH">
			<div class="logo autoH">
				<img src="images/logo.png" width="100%">
			</div>
		</div>
		<div class="middle">
			<form id="theForm">
				<div class="forminput">
					<input type="text" id="expressNum" name="expressNum" placeholder="请输入快递单号...">
					<input id="PageContext" type="hidden" value="${pageContext.request.contextPath}" />
					<div class="submBtn"></div>
				</div>
			</form>
		</div>
		<div class="funContdiv">
			<div class="funCont">
				<div class="userFun">
					<p class="funIcon userFunColor1"></p>
					<p class="funTxt">个人中心</p>
				</div>
				<div class="userFun">
					<p class="funIcon userFunColor2"></p>
					<p class="funTxt">懒人排行</p>
				</div>
				<div class="userFun">
					<p class="funIcon userFunColor3"></p>
					<p class="funTxt">取货二维码</p>
				</div>
				<div class="userFun">
					<p class="funIcon userFunColor4"></p>
					<p class="funTxt">我的快件</p>
				</div>
					<div class="userFun" id="userFun5">
						<p class="funIcon userFunColor5"></p>
						<p class="funTxt">快递助手</p>
					</div>
					<div class="userFun">
						<p class="funIcon userFunColor6"></p>
						<p class="funTxt">退出登录</p>
					</div>
			</div>
		</div>
	
		<div class="footer">
			<p class="copytxt">&copy;新职课版权所有</p>
		</div>
	</div>
	<script type="text/javascript">
	var isUser;
	var userPhone;
	$(function(){
		$.getJSON("/wx/userInfo.do",null,function(data){
			//{status:0/1,result:手机号}
			userPhone = data.result;
			if(data.status == 0){
				isUser = true;
				$("#userFun5").hide();
			}else{
				isUser = false;
			}
			//layer.msg("欢迎您:"+userPhone);
		});
	});

	$(function(){
		var pageContextVal = $("#PageContext").val();
		$(".userFun").click(function(){
			var clickNum = $(this).index();
			switch(clickNum){
				//个人中心
				case(0): 
					window.location.href= "wxUserhome.html"; 
					break;
				case(1): 
					window.location.href= "lazyboard.html"; 
					break;
				case(2): window.location.href= "/wx/createQRCode.do?type=user"; break;
				case(3): window.location.href= "expressList.html"; break;
				case(4): window.location.href= "expressAssist.html"; break;
				case(5):
					//1.	告知服务器
						$.getJSON("/wx/logout.do",null,function(data){
							window.location.href= "login.html";
						});
					break;
			}
		});

		var initFunc = function(){
			var windowH = $(document).height();
			var windowW = $(document).width();

			$(".content").css({"height": windowH+"px"});

			var contentW = $(".content").width();
			var contentH = $(".content").height();

			var contH = windowH / 3;
			$(".autoH").css({"height": contH+"px"});

			// userFunH  content
			var middleH = $(".middle").height() + 40;
			var userFunH = contentH - contH - middleH - 30 -20; //footer,userfun(margin)
			$(".funContdiv").css({"height":userFunH+"px"});

			var funIconH = $(".funIcon").width(); 
			$(".funIcon").css({"height": funIconH+"px","line-height": funIconH+"px","border-radius": funIconH/2 +"px","font-size":funIconH/2 +"px"});

		};

		initFunc();

		$(window).resize(function(){
			initFunc();
		});

		// input focus
		$(".middle .forminput input").focus(function(){
			$(".middle .forminput").css({"border":"1px solid rgba(31,114,255,.75)","box-shadow":"0 0 8px rgba(31,114,255,.5)"});
		});

		// input blur
		$(".middle .forminput input").blur(function(){
			$(".middle .forminput").css({"border":"1px solid #333333","box-shadow":"none"});
		});

		//submit arrow
		$(".submBtn").click(function(){
			var expressNum = $("#expressNum").val();//快递单号
			 $.ajax({
				    type:'GET',
				    url:pageContextVal+'/ul/indexQueryExpress',
				    data:{'expressNum':expressNum},
				    dataType: "json",
				    success:function(data){
				    	var jsontmp = data;
						switch(jsontmp.code) {
							case "1" : rzAlert("操作提示",jsontmp.message); break;
							case "0" : 
								rzAlert("操作提示",jsontmp.message);
								break;
						}
				    },
				    error:function(){
				      
				    }
				});
		});
	});
	</script>
</body>
</html>

后台

public class ExpressController {
    @ResponseBody("/wx/findExpressByUserPhone.do")
    public String findByUserPhone(HttpServletRequest request, HttpServletResponse response){
        User wxUser = UserUtil.getWxUser(request.getSession());
        String userPhone = wxUser.getUserPhone();
        List<Express> list = ExpressService.findByUserPhone(userPhone);
        List<BootStrapTableExpress> list2 = new ArrayList<>();
        for(Express e:list){
            String inTime = DateFormatUtil.format(e.getInTime());
            String outTime = e.getOutTime()==null?"未出库":DateFormatUtil.format(e.getOutTime());
            String status = e.getStatus()==0?"待取件":"已取件";
            String code = e.getCode()==null?"已取件":e.getCode();
            BootStrapTableExpress e2 = new BootStrapTableExpress(e.getId(),e.getNumber(),e.getUsername(),e.getUserPhone(),e.getCompany(),code,inTime,outTime,status,e.getSysPhone());
            list2.add(e2);
        }
        Message msg = new Message();
        if(list.size()==0){
            msg.setStatus(-1);
        }else{
            msg.setStatus(0);
            Stream<BootStrapTableExpress> status0Express = list2.stream().filter(express -> {
                if (express.getStatus().equals("待取件")) {
                    return true;
                } else {
                    return false;
                }
            }).sorted((o1,o2) -> {
                long o1Time = DateFormatUtil.toTime(o1.getInTime());
                long o2Time = DateFormatUtil.toTime(o2.getInTime());
                return (int)(o1Time-o2Time);
            });
            Stream<BootStrapTableExpress> status1Express = list2.stream().filter(express -> {
                if (express.getStatus().equals("已取件")) {
                    return true;
                } else {
                    return false;
                }
            }).sorted((o1,o2) -> {
                long o1Time = DateFormatUtil.toTime(o1.getInTime());
                long o2Time = DateFormatUtil.toTime(o2.getInTime());
                return (int)(o1Time-o2Time);
            });
            Object[] s0 = status0Express.toArray();
            Object[] s1 = status1Express.toArray();
            Map data = new HashMap<>();
            data.put("status0",s0);
            data.put("status1",s1);
            msg.setData(data);
        }
        String json = JSONUtil.toJSON(msg.getData());
        return json;
    }

    @ResponseBody("/wx/userExpressList.do")
    public String expressList(HttpServletRequest request,HttpServletResponse response){
        String userPhone = request.getParameter("userPhone");
        List<Express> list = ExpressService.findByUserPhoneAndStatus(userPhone, 0);
        List<BootStrapTableExpress> list2 = new ArrayList<>();
        for(Express e:list){
            String inTime = DateFormatUtil.format(e.getInTime());
            String outTime = e.getOutTime()==null?"未出库":DateFormatUtil.format(e.getOutTime());
            String status = e.getStatus()==0?"待取件":"已取件";
            String code = e.getCode()==null?"已取件":e.getCode();
            BootStrapTableExpress e2 = new BootStrapTableExpress(e.getId(),e.getNumber(),e.getUsername(),e.getUserPhone(),e.getCompany(),code,inTime,outTime,status,e.getSysPhone());
            list2.add(e2);
        }
        Message msg = new Message();
        if(list.size() == 0){
            msg.setStatus(-1);
            msg.setResult("未查询到快递");
        }else{
            msg.setStatus(0);
            msg.setResult("查询成功");
            msg.setData(list2);
        }
        return JSONUtil.toJSON(msg);
    }

过滤器

防止用户不登录直接进行跳转

@WebFilter({"/index.html"})
public class UserFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpSession session = ((HttpServletRequest)req).getSession();
        User wxUser = UserUtil.getWxUser(session);
        if(wxUser != null)
            chain.doFilter(req, resp);
        else
            ((HttpServletResponse)resp).sendRedirect("login.html");
    }

    public void init(FilterConfig config) throws ServletException {

    }

9、过程梳理

创建数据库表格

编写DAO

编写Service

编写Controller

前后端的交互

前端发起ajax→XXServlet→Controller→Service→DAO→数据库

10、前台实现

需引入相应的jQuery包

Express

分页

<body>
		<table id="express_list"></table>
		<script>
			$(function(){
				$("#express_list").bootstrapTable({
					url:"/express/list.do",//数据地址
					striped:true,//是否显示行的间隔
					pageNumber:1,//初始化加载第几页
					pagination:true,//是否分页
					sidePagination:'server',
					pageSize:5,
					pageList:[5,10,20],
					showRefresh:true,
					queryParams:function(params){
						var temp = {
							offset:params.offset,
							pageNumber:params.limit
						};
						return temp;
					},
					columns:[
						{
							title:"编号",
							field:"id",
							sortable:false
						},
						{
							title:"单号",
							field:"number",
							sortable:false
						},
						{
							title:"姓名",
							field:"username",
							sortable:false
						},
						{
							title:"电话",
							field:"userPhone",
							sortable:false
						},
						{
							title:"快递公司",
							field:"company",
							sortable:false
						},
						{
							title:"取件码",
							field:"code",
							sortable:false
						},
						{
							title:"入库时间",
							field:"inTime",
							sortable:false
						},
						{
							title:"出库时间",
							field:"outTime",
							sortable:false
						},
						{
							title:"状态",
							field:"status",
							sortable:false
						},
						{
							title:"录入人电话",
							field:"sysPhone",
							sortable:false
						}
					]
				});
			});
		</script>

新增

<script>
        $(function(){
            $("#form").submit(function(){
                var windowId = layer.load();
                var number = $("input:eq(0)").val();
                var company = $("input:eq(1)").val();
                var username = $("input:eq(2)").val();
                var userPhone = $("input:eq(3)").val();
                $.post("/express/insert.do",{
                    number:number,
                    company:company,
                    username:username,
                    userPhone:userPhone
                    },function(data){
                        layer.close(windowId);
                        layer.msg(data.result);
                        if(data.status == 0){
                            //录入成功
                            $("input").val("");
                            $("input:eq(1)").val("顺丰速运");
                        }else{
                            //录入失败
                        }
                });

                return false;
            });


        });
    </script>

删除

<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
	<script>
		$(".header:eq(1),.content:eq(1)").hide();
		var expressId = null;
		$(function(){
			$("#find").click(function(){
				var windowId = layer.load();
				var number = $("#number").val();
				$.getJSON("/express/find.do",{number:number},function(data){
					layer.close(windowId);
					//data:{"status":0,"result":"查询成功","data":{"id":2,"number":"124","username":"张三","userPhone":"13843838438","company":"京东快递","code":"213456","inTime":"Jul 21, 2020, 4:26:21 PM","status":0,"sysPhone":"18888888888"}}
					layer.msg(data.result);
					if(data.status == 0){
						$(".header:eq(1),.content:eq(1)").fadeIn(1000);
						expressId = data.data.id;
						$("input:eq(1)").val(data.data.number);
						$("input:eq(2)").val(data.data.company);
						$("input:eq(3)").val(data.data.username);
						$("input:eq(4)").val(data.data.userPhone);
						$("input:eq(1),input:eq(2),input:eq(3),input:eq(4)").prop("disabled",true)
						if(data.data.status == 0){
							//未签收
							$("#status").html("未签收");
						}else{
							//已签收
							$("#status").html("已签收");
						}
					}
				})
			});

			$("#delete").click(function(){
				var windowId = layer.load();
				$.getJSON("/express/delete.do",{id:expressId},function(data){
					layer.close(windowId);
					layer.msg(data.result);
					if(data.status == 0){
						$(".header:eq(1),.content:eq(1)").hide();
					}
				});
			});
		});
	</script>

修改

<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
<script>
	$(".header:eq(1),.content:eq(1)").hide();
	var expressId = null;
	var g_userPhone = null;
	$(function(){
		$("#find").click(function(){
			var windowId = layer.load();
			var number = $("#number").val();
			$.getJSON("/express/find.do",{number:number},function(data){
				layer.close(windowId);
				//data:{"status":0,"result":"查询成功","data":{"id":2,"number":"124","username":"张三","userPhone":"13843838438","company":"京东快递","code":"213456","inTime":"Jul 21, 2020, 4:26:21 PM","status":0,"sysPhone":"18888888888"}}
				layer.msg(data.result);
				if(data.status == 0){
					$(".header:eq(1),.content:eq(1)").fadeIn(1000);
					expressId = data.data.id;
					g_userPhone = data.data.userPhone;
					$("input:eq(1)").val(data.data.number);
					$("input:eq(2)").val(data.data.company);
					$("input:eq(3)").val(data.data.username);
					$("input:eq(4)").val(data.data.userPhone);
					if(data.data.status == 0){
						//未签收
						$(".status:eq(1)").prop("checked",true);
					}else{
						//已签收
						$(".status:eq(0)").prop("checked",true);
					}
				}
			})
		});

		$("#update").click(function(){
			var windowId = layer.load();
			var number = $("input:eq(1)").val();
			var company = $("input:eq(2)").val();
			var username = $("input:eq(3)").val();
			var userPhone = $("input:eq(4)").val();

			var status = $(".status:checked").val();
			var express = {
				id:expressId,
				number:number,
				company:company,
				username:username,
				status:status
			};
			if(userPhone != g_userPhone){
				express.userPhone = userPhone;
			}
			$.getJSON("/express/update.do",express,function(data){
				layer.close(windowId);
				layer.msg(data.result)

				if(data.status == 0){
					//修改成功的
					$(".header:eq(1),.content:eq(1)").hide();
				}
			})
		});
	});
</script>

User与Courier与其雷同,按照实体类修改相关参数即可

11、新知识引入——layer
 

layer 至今仍作为 layui 的代表作,它的受众广泛并非偶然,而是这数年来的坚持、不弃的执念,将那些不屑的眼光转化为应得的尊重,不断完善和维护、不断建设和提升社区服务,在 Web 开发者的圈子里口口相传,乃至于成为今天的 layui 最强劲的源动力。目前,layer 已然成为网页弹出层的首选交互方案,几乎随处可见。

学习链接:

layer弹层组件开发文档 - Layui

12、新知识引入——内网穿透

内网穿透即NAT穿透,网络连接时术语,计算机是局域网内时,外网与内网的计算机节点需要连接通信,有时就会出现不支持内网穿透。就是说映射端口,能让外网的电脑找到处于内网的电脑,提高下载速度。不管是内网穿透还是其他类型的网络穿透,都是网络穿透的统一方法来研究和解决。NAT穿透,nat穿透中有关于网络穿透的详细信息。

使用步骤(图片)

登录网站

Sunny-Ngrok内网转发内网穿透 - 国内内网映射服务器

注册登录

下一步

需要两元的认证费

之后

配置自己的域名(我用的同学的)

此步骤省略

13、发送短信及验证码

短信

public static boolean send(String phoneNumber,String code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GJVun7NhPS8FMgSqqS4", "TgTLk8KVJjESFu6iC1jTHsVMK53z5Q");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2022-3-14");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        request.putQueryParameter("SignName", "快件e栈");
        request.putQueryParameter("TemplateCode", "SMS_196641606");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            String json = response.getData();
            Gson g = new Gson();
            HashMap result = g.fromJson(json, HashMap.class);
            if("OK".equals(result.get("Message"))) {
                return true;
            }else{
                System.out.println("短信发送失败,原因:"+result.get("Message"));
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }
    public static boolean loginSMS(String phoneNumber,String code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GKsiFzUmLZ8Qnx1Sfza", "jUhIqqk3wwvhm2T1HOUVbCmIOWNE0O");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        request.putQueryParameter("SignName", "快递e栈");
        request.putQueryParameter("TemplateCode", "SMS_204295076");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+ code +"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            String json = response.getData();
            Gson g = new Gson();
            HashMap result = g.fromJson(json, HashMap.class);
            if("OK".equals(result.get("Message"))) {
                return true;
            }else{
                System.out.println("短信发送失败,原因:"+result.get("Message"));
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return false;
    }

验证码

14、运行效果

控制台

Courier:(四个页面,相应为分页、新增、查询、修改)

Express:(四个页面,相应为分页、新增、查询、修改)

 

User:(四个页面,相应为分页、新增、查询、修改)

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐