0


学生宿舍管理系统

1.项目介绍:

学生宿舍管理系统,管理员可以对宿舍、宿舍楼、学生进行增删改查操作

2.项目技术:

前端:jsp、css、JavaScript、Jquery

后端:Servlet、mvc

3.开发环境:

JAVA版本:JDK1.8

类型:IDEA

Tomcat版本:Tomcat 7-10

数据库:MySql

硬件类型:Win、Mac

4.功能介绍:

4.1.模块登录:

4.2.其他模块:

4.2.1.宿舍楼管理:

4.2.2.宿舍管理:

4.2.3.学生管理:

5. 代码目录:

6.代码模块:

dto:

package com.roadjava.studentroom.bean.dto;

/**
 * 封装删除语句参数的类
 */
public class DeleteParam {
    private StringBuilder sql;
    private Long[] ids;

    public StringBuilder getSql() {
        return sql;
    }

    public void setSql(StringBuilder sql) {
        this.sql = sql;
    }

    public Long[] getIds() {
        return ids;
    }

    public void setIds(Long[] ids) {
        this.ids = ids;
    }

}

entity:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.bean.entity;

public class BuildingDO {
    private Long id;
    private String no;
    private String completedDate;
    private String type;
    private String uniqueNo;

    public BuildingDO() {
    }

    public Long getId() {
        return this.id;
    }

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

    public String getNo() {
        return this.no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getCompletedDate() {
        return this.completedDate;
    }

    public void setCompletedDate(String completedDate) {
        this.completedDate = completedDate;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUniqueNo() {
        return format(this.type, this.no);
    }

    public static String format(String type, String no) {
        if ("M".equals(type)) {
            type = "男";
        } else {
            type = "女";
        }

        return type + "-" + no;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.bean.entity;

public class DormitoryDO {
    private Long id;
    private String no;
    private Long dormitoryBuildingId;
    private String buildingUniqueNo;

    public DormitoryDO() {
    }

    public Long getId() {
        return this.id;
    }

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

    public String getNo() {
        return this.no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public Long getDormitoryBuildingId() {
        return this.dormitoryBuildingId;
    }

    public void setDormitoryBuildingId(Long dormitoryBuildingId) {
        this.dormitoryBuildingId = dormitoryBuildingId;
    }

    public String getBuildingUniqueNo() {
        return this.buildingUniqueNo;
    }

    public void setBuildingUniqueNo(String buildingUniqueNo) {
        this.buildingUniqueNo = buildingUniqueNo;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.bean.entity;

public class ManagerDO {
    private Long id;
    private String userName;
    private String pwd;

    public ManagerDO() {
    }

    public Long getId() {
        return this.id;
    }

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

    public String getUserName() {
        return this.userName;
    }

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

    public String getPwd() {
        return this.pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.bean.entity;

public class StudentDO {
    private Long id;
    private String name;
    private String gender;
    private String no;
    private String dept;
    private String grade;
    private Long dormitoryId;
    private Long buildingId;
    private String dormitoryNo;
    private String buildingUniqueNo;

    public StudentDO() {
    }

    public String getDormitoryNo() {
        return this.dormitoryNo;
    }

    public void setDormitoryNo(String dormitoryNo) {
        this.dormitoryNo = dormitoryNo;
    }

    public Long getId() {
        return this.id;
    }

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

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNo() {
        return this.no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public Long getDormitoryId() {
        return this.dormitoryId;
    }

    public void setDormitoryId(Long dormitoryId) {
        this.dormitoryId = dormitoryId;
    }

    public String getDept() {
        return this.dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public String getGrade() {
        return this.grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public Long getBuildingId() {
        return this.buildingId;
    }

    public void setBuildingId(Long buildingId) {
        this.buildingId = buildingId;
    }

    public String getBuildingUniqueNo() {
        return this.buildingUniqueNo;
    }

    public void setBuildingUniqueNo(String buildingUniqueNo) {
        this.buildingUniqueNo = buildingUniqueNo;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}

filter:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebFilter(
    filterName = "characterEncodingFilter",
    urlPatterns = {"/*"},
    initParams = {@WebInitParam(
    name = "encoding",
    value = "UTF-8"
)}
)
public class CharacterEncodingFilter implements Filter {
    private String encoding = null;

    public CharacterEncodingFilter() {
    }

    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest)req;
        HttpServletResponse httpServletResponse = (HttpServletResponse)resp;
        httpServletRequest.setCharacterEncoding(this.encoding);
        httpServletResponse.setCharacterEncoding(this.encoding);
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
        this.encoding = config.getInitParameter("encoding");
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.filter;

import com.roadjava.studentroom.bean.entity.ManagerDO;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebFilter(
    filterName = "characterEncodingFilter",
    urlPatterns = {"/building", "/dormitory", "/student", "/manager"}
)
public class XAuthFilter implements Filter {
    public XAuthFilter() {
    }

    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest)req;
        HttpServletResponse httpServletResponse = (HttpServletResponse)resp;
        ManagerDO manager = (ManagerDO)httpServletRequest.getSession().getAttribute("manager");
        if (manager == null) {
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/index.jsp");
        } else {
            chain.doFilter(req, resp);
        }
    }

    public void init(FilterConfig config) throws ServletException {
    }
}

req:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.req;

import com.roadjava.studentroom.util.Constants;

public class BaseRequest {
    private int pageSize;
    private int pageNow;

    public BaseRequest() {
        this.pageSize = Constants.PAGE_SIZE;
    }

    public int getStart() {
        return (this.pageNow - 1) * this.pageSize;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public int getpageNow() {
        return this.pageNow;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.req;

public class DormitoryBuildingRequest extends BaseRequest {
    private String no;

    public DormitoryBuildingRequest() {
    }

    public String getNo() {
        return this.no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public boolean selectAll() {
        return this.getPageSize() == -1;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.req;

public class DormitoryRequest extends BaseRequest {
    private String no;
    private Long dormitoryBuildingId;

    public DormitoryRequest() {
    }

    public String getNo() {
        return this.no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public Long getDormitoryBuildingId() {
        return this.dormitoryBuildingId;
    }

    public void setDormitoryBuildingId(Long dormitoryBuildingId) {
        this.dormitoryBuildingId = dormitoryBuildingId;
    }

    public boolean selectAll() {
        return this.getPageSize() == -1;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.req;

public class StudentRequest extends BaseRequest {
    private String studentNo;

    public StudentRequest() {
    }

    public String getStudentNo() {
        return this.studentNo;
    }

    public void setStudentNo(String studentNo) {
        this.studentNo = studentNo;
    }
}

res:


  // IntelliJ API Decompiler stub source generated from a class file
  // Implementation of methods is not available

package com.roadjava.studentroom.res;

public class ResultDTO <T> {
    private java.lang.String errCode;
    private java.lang.String errMsg;
    private java.lang.Boolean success;
    private T data;
    private java.lang.Long total;
    private java.util.Map<java.lang.String,java.lang.Object> attributes;

    private ResultDTO() { /* compiled code */ }

    public void addAttr(java.lang.String key, java.lang.Object value) { /* compiled code */ }

    public static <T> com.roadjava.studentroom.res.ResultDTO<T> buildSuccess(T t, java.lang.Number total) { /* compiled code */ }

    public static <T> com.roadjava.studentroom.res.ResultDTO<T> buildEmptySuccess() { /* compiled code */ }

    public static <T> com.roadjava.studentroom.res.ResultDTO<T> buildSuccess(T t) { /* compiled code */ }

    public static <T> com.roadjava.studentroom.res.ResultDTO<T> buildFailure(java.lang.String code, java.lang.String errMsg) { /* compiled code */ }

    public static <T> com.roadjava.studentroom.res.ResultDTO<T> buildFailure(java.lang.String errMsg) { /* compiled code */ }

    public java.lang.String getErrCode() { /* compiled code */ }

    public void setErrCode(java.lang.String errCode) { /* compiled code */ }

    public java.lang.String getErrMsg() { /* compiled code */ }

    public void setErrMsg(java.lang.String errMsg) { /* compiled code */ }

    public java.lang.Boolean getSuccess() { /* compiled code */ }

    public void setSuccess(java.lang.Boolean success) { /* compiled code */ }

    public T getData() { /* compiled code */ }

    public void setData(T data) { /* compiled code */ }

    public java.lang.Long getTotal() { /* compiled code */ }

    public void setTotal(java.lang.Long total) { /* compiled code */ }

    public java.util.Map<java.lang.String,java.lang.Object> getAttributes() { /* compiled code */ }

    public void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes) { /* compiled code */ }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.res;

import com.roadjava.studentroom.util.Constants;
import java.util.Vector;

public class TableDataDTO {
    private Vector<Vector<Object>> data;
    private int pageNow;
    private int totalCount;
    private String searchWord;

    public TableDataDTO() {
    }

    public Vector<Vector<Object>> getData() {
        return this.data;
    }

    public void setData(Vector<Vector<Object>> data) {
        this.data = data;
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageNow() {
        return this.pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public String getSearchWord() {
        return this.searchWord;
    }

    public void setSearchWord(String searchWord) {
        this.searchWord = searchWord;
    }

    public int getPageCount() {
        int pageCount = false;
        int pageCount;
        if (this.totalCount % Constants.PAGE_SIZE == 0) {
            pageCount = this.totalCount / Constants.PAGE_SIZE;
        } else {
            pageCount = this.totalCount / Constants.PAGE_SIZE + 1;
        }

        return pageCount;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.res;

import com.roadjava.studentroom.util.Constants;
import java.util.Vector;

public class TableResult<T> {
    private Vector<T> data;
    private int totalCount;
    private int pageNow;
    private String searchWord;

    public TableResult() {
    }

    public Vector<T> getData() {
        return this.data;
    }

    public void setData(Vector<T> data) {
        this.data = data;
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageNow() {
        return this.pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public String getSearchWord() {
        return this.searchWord;
    }

    public void setSearchWord(String searchWord) {
        this.searchWord = searchWord;
    }

    public int getPageCount() {
        int pageCount = false;
        int pageCount;
        if (this.totalCount % Constants.PAGE_SIZE == 0) {
            pageCount = this.totalCount / Constants.PAGE_SIZE;
        } else {
            pageCount = this.totalCount / Constants.PAGE_SIZE + 1;
        }

        return pageCount;
    }
}

service-->impl:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service.impl;

import com.roadjava.studentroom.bean.dto.DeleteParam;
import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.bean.entity.DormitoryDO;
import com.roadjava.studentroom.req.DormitoryBuildingRequest;
import com.roadjava.studentroom.req.DormitoryRequest;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BaseServiceSupport;
import com.roadjava.studentroom.service.BuildingService;
import com.roadjava.studentroom.service.DormitoryService;
import com.roadjava.studentroom.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.function.Function;
import java.util.stream.Collectors;

public class BuildingServiceImpl extends BaseServiceSupport implements BuildingService {
    public BuildingServiceImpl() {
    }

    public boolean add(BuildingDO buildingDO) {
        String sql = "insert into dormitory_building(no,completed_date,type) values(?,?,?)";
        return this.doAdd(sql, new Object[]{buildingDO.getNo(), buildingDO.getCompletedDate(), buildingDO.getType()});
    }

    public boolean delete(Long[] ids) {
        List<DeleteParam> conditionList = new ArrayList();
        List<Long> dormitoryIds = new ArrayList();
        DormitoryService dormitoryService = new DormitoryServiceImpl();
        Long[] var8 = ids;
        int var7 = ids.length;

        for(int var6 = 0; var6 < var7; ++var6) {
            Long buildingId = var8[var6];
            DormitoryRequest dormitoryRequest = new DormitoryRequest();
            dormitoryRequest.setPageSize(-1);
            dormitoryRequest.setDormitoryBuildingId(buildingId);
            Vector<DormitoryDO> vector = dormitoryService.getVector(dormitoryRequest);
            List<Long> list = (List)vector.stream().map(DormitoryDO::getId).collect(Collectors.toList());
            dormitoryIds.addAll(list);
        }

        StringBuilder dormitoryDelsql;
        DeleteParam dormitoryDeleteParam;
        if (!dormitoryIds.isEmpty()) {
            dormitoryDelsql = new StringBuilder("delete from student where dormitory_id in (");
            dormitoryDeleteParam = new DeleteParam();
            dormitoryDeleteParam.setSql(dormitoryDelsql);
            dormitoryDeleteParam.setIds((Long[])dormitoryIds.toArray(new Long[dormitoryIds.size()]));
            conditionList.add(dormitoryDeleteParam);
        }

        dormitoryDelsql = new StringBuilder("delete from dormitory where dormitory_building_id in ( ");
        dormitoryDeleteParam = new DeleteParam();
        dormitoryDeleteParam.setSql(dormitoryDelsql);
        dormitoryDeleteParam.setIds(ids);
        conditionList.add(dormitoryDeleteParam);
        StringBuilder buildingDelSql = new StringBuilder("delete from dormitory_building where id in ( ");
        DeleteParam buildingDeleteParam = new DeleteParam();
        buildingDeleteParam.setSql(buildingDelSql);
        buildingDeleteParam.setIds(ids);
        conditionList.add(buildingDeleteParam);
        return this.doDelete(conditionList);
    }

    public boolean update(BuildingDO buildingDO) {
        String sql = "update dormitory_building set no = ?,completed_date = ?   ,type = ? where id = ? ";
        return this.doUpdate(sql, new Object[]{buildingDO.getNo(), buildingDO.getCompletedDate(), buildingDO.getType(), buildingDO.getId()});
    }

    public TableResult<BuildingDO> retrieveList(DormitoryBuildingRequest req) {
        TableResult<BuildingDO> retDTO = new TableResult();
        StringBuilder sql = new StringBuilder("select id,no,date_format(completed_date,'%Y-%m-%d') as completed_date,type  from dormitory_building where 1=1 ");
        if (req.getNo() != null && !"".equals(req.getNo().trim())) {
            sql.append("and no like '%");
            sql.append(req.getNo());
            sql.append("%'");
        }

        sql.append(" order by id desc  ");
        if (!req.selectAll()) {
            sql.append(" limit ");
            sql.append(req.getStart()).append(",").append(req.getPageSize());
        }

        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn == null) {
                return null;
            }

            ps = conn.prepareStatement(sql.toString());
            resultSet = ps.executeQuery();
            Vector data = new Vector();

            while(resultSet.next()) {
                long id = resultSet.getLong("id");
                String no = resultSet.getString("no");
                String completed_date = resultSet.getString("completed_date");
                String type = resultSet.getString("type");
                BuildingDO oneVector = new BuildingDO();
                oneVector.setId(id);
                oneVector.setNo(no);
                oneVector.setCompletedDate(completed_date);
                oneVector.setType(type);
                data.addElement(oneVector);
            }

            sql.setLength(0);
            sql.append("select count(*) from dormitory_building where 1=1 ");
            if (req.getNo() != null && !"".equals(req.getNo().trim())) {
                sql.append("and no like '%");
                sql.append(req.getNo());
                sql.append("%'");
            }

            ps = conn.prepareStatement(sql.toString());
            resultSet = ps.executeQuery();

            while(resultSet.next()) {
                int totalCount = resultSet.getInt(1);
                retDTO.setTotalCount(totalCount);
            }

            retDTO.setData(data);
            retDTO.setPageNow(req.getpageNow());
            TableResult var15 = retDTO;
            return var15;
        } catch (SQLException var18) {
            var18.printStackTrace();
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return null;
    }

    public BuildingDO retrieveOneById(Long id) {
        StringBuilder sql = new StringBuilder("select id,no, date_format(completed_date,'%Y-%m-%d') as completed_date,  type  from dormitory_building where id =? ");
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn == null) {
                return null;
            } else {
                ps = conn.prepareStatement(sql.toString());
                ps.setLong(1, id);
                resultSet = ps.executeQuery();
                BuildingDO resultDO = new BuildingDO();

                while(resultSet.next()) {
                    String no = resultSet.getString("no");
                    String completed_date = resultSet.getString("completed_date");
                    String type = resultSet.getString("type");
                    resultDO.setId(id);
                    resultDO.setNo(no);
                    resultDO.setCompletedDate(completed_date);
                    resultDO.setType(type);
                }

                BuildingDO var11 = resultDO;
                return var11;
            }
        } catch (SQLException var14) {
            var14.printStackTrace();
            return null;
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }
    }

    public Vector<BuildingDO> getVector(DormitoryBuildingRequest req) {
        TableResult<BuildingDO> result = this.retrieveList(req);
        return result.getData();
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service.impl;

import com.roadjava.studentroom.bean.dto.DeleteParam;
import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.bean.entity.DormitoryDO;
import com.roadjava.studentroom.req.DormitoryRequest;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BaseServiceSupport;
import com.roadjava.studentroom.service.DormitoryService;
import com.roadjava.studentroom.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class DormitoryServiceImpl extends BaseServiceSupport implements DormitoryService {
    public DormitoryServiceImpl() {
    }

    public boolean add(DormitoryDO dormitoryDO) {
        String sql = "insert into dormitory(no,dormitory_building_id) values(?,?)";
        return this.doAdd(sql, new Object[]{dormitoryDO.getNo(), dormitoryDO.getDormitoryBuildingId()});
    }

    public boolean delete(Long[] ids) {
        List<DeleteParam> conditionList = new ArrayList();
        StringBuilder studentDeleteSql = new StringBuilder("delete from student where dormitory_id in (");
        DeleteParam studentDeleteParam = new DeleteParam();
        studentDeleteParam.setSql(studentDeleteSql);
        studentDeleteParam.setIds(ids);
        conditionList.add(studentDeleteParam);
        StringBuilder sql = new StringBuilder("delete from dormitory where id in ( ");
        DeleteParam deleteParam = new DeleteParam();
        deleteParam.setSql(sql);
        deleteParam.setIds(ids);
        conditionList.add(deleteParam);
        return this.doDelete(conditionList);
    }

    public boolean update(DormitoryDO dormitoryDO) {
        String sql = "update dormitory set no = ?,dormitory_building_id=?   where id = ? ";
        return this.doUpdate(sql, new Object[]{dormitoryDO.getNo(), dormitoryDO.getDormitoryBuildingId(), dormitoryDO.getId()});
    }

    public TableResult<DormitoryDO> retrieveList(DormitoryRequest req) {
        TableResult<DormitoryDO> retDTO = new TableResult();
        StringBuilder sql = new StringBuilder();
        sql.append("select a.id,a.no,b.no as build_no,b.type from dormitory a ");
        sql.append(" left join dormitory_building b  on a.dormitory_building_id = b.id ");
        sql.append(" where 1=1 ");
        if (req.getNo() != null && !"".equals(req.getNo().trim())) {
            sql.append(" and a.no like '%");
            sql.append(req.getNo());
            sql.append("%'");
        }

        if (req.getDormitoryBuildingId() != null) {
            sql.append(" and a.dormitory_building_id = " + req.getDormitoryBuildingId());
        }

        sql.append(" order by a.id desc  ");
        if (!req.selectAll()) {
            sql.append(" limit ");
            sql.append(req.getStart()).append(",").append(req.getPageSize());
        }

        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn != null) {
                ps = conn.prepareStatement(sql.toString());
                resultSet = ps.executeQuery();
                Vector data = new Vector();

                while(resultSet.next()) {
                    long id = resultSet.getLong("id");
                    String no = resultSet.getString("no");
                    String buildingNo = resultSet.getString("build_no");
                    String type = resultSet.getString("type");
                    DormitoryDO oneVector = new DormitoryDO();
                    oneVector.setId(id);
                    oneVector.setNo(no);
                    oneVector.setBuildingUniqueNo(BuildingDO.format(type, buildingNo));
                    data.addElement(oneVector);
                }

                sql.setLength(0);
                sql.append("select count(*) from dormitory where 1=1 ");
                if (req.getNo() != null && !"".equals(req.getNo().trim())) {
                    sql.append("and no like '%");
                    sql.append(req.getNo());
                    sql.append("%'");
                }

                ps = conn.prepareStatement(sql.toString());
                resultSet = ps.executeQuery();

                while(resultSet.next()) {
                    int totalCount = resultSet.getInt(1);
                    retDTO.setTotalCount(totalCount);
                }

                retDTO.setData(data);
                retDTO.setPageNow(req.getpageNow());
                TableResult var15 = retDTO;
                return var15;
            }
        } catch (SQLException var18) {
            var18.printStackTrace();
            return null;
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return null;
    }

    public DormitoryDO retrieveOneById(Long id) {
        StringBuilder sql = new StringBuilder();
        sql.append("select id,no,dormitory_building_id from dormitory where id =? ");
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn == null) {
                return null;
            }

            ps = conn.prepareStatement(sql.toString());
            ps.setLong(1, id);
            resultSet = ps.executeQuery();
            DormitoryDO resultDO = new DormitoryDO();

            while(resultSet.next()) {
                String no = resultSet.getString(2);
                resultDO.setId(id);
                resultDO.setNo(no);
                resultDO.setDormitoryBuildingId(resultSet.getLong(3));
            }

            DormitoryDO var9 = resultDO;
            return var9;
        } catch (SQLException var12) {
            var12.printStackTrace();
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return null;
    }

    public Vector<DormitoryDO> getVector(DormitoryRequest req) {
        TableResult<DormitoryDO> result = this.retrieveList(req);
        return result.getData();
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service.impl;

import com.roadjava.studentroom.bean.entity.ManagerDO;
import com.roadjava.studentroom.service.ManagerService;
import com.roadjava.studentroom.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ManagerServiceImpl implements ManagerService {
    public ManagerServiceImpl() {
    }

    public boolean validateManagerInfo(ManagerDO managerDO) {
        String sql = "select pwd from manager where user_name = ? ";
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn == null) {
                return false;
            }

            ps = conn.prepareStatement(sql);
            ps.setString(1, managerDO.getUserName());
            resultSet = ps.executeQuery();
            boolean validateOk = false;

            while(resultSet.next()) {
                String pwd = resultSet.getString(1);
                if (managerDO.getPwd().equals(pwd)) {
                    validateOk = true;
                }
            }

            boolean var9 = validateOk;
            return var9;
        } catch (SQLException var12) {
            var12.printStackTrace();
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return false;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service.impl;

import com.roadjava.studentroom.bean.dto.DeleteParam;
import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.bean.entity.StudentDO;
import com.roadjava.studentroom.req.StudentRequest;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BaseServiceSupport;
import com.roadjava.studentroom.service.StudentService;
import com.roadjava.studentroom.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class StudentServiceImpl extends BaseServiceSupport implements StudentService {
    public StudentServiceImpl() {
    }

    public boolean add(StudentDO studentDO) {
        if (this.checkHasExist(studentDO.getNo())) {
            throw new RuntimeException("学号已存在");
        } else {
            String sql = "insert into student(name,gender,no,dept,grade,dormitory_id) values(?,?,?,?,?,?)";
            return this.doAdd(sql, new Object[]{studentDO.getName(), studentDO.getGender(), studentDO.getNo(), studentDO.getDept(), studentDO.getGrade(), studentDO.getDormitoryId()});
        }
    }

    private boolean checkHasExist(String no) {
        String sql = "select count(1) from student where no = ? ";
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn != null) {
                ps = conn.prepareStatement(sql);
                ps.setString(1, no);
                resultSet = ps.executeQuery();
                boolean hasExist = false;

                boolean var9;
                while(resultSet.next()) {
                    int count = resultSet.getInt(1);
                    if (count != 0) {
                        hasExist = true;
                        var9 = hasExist;
                        return var9;
                    }
                }

                var9 = hasExist;
                return var9;
            }

            return false;
        } catch (SQLException var12) {
            var12.printStackTrace();
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return false;
    }

    public boolean delete(Long[] ids) {
        StringBuilder sqlBuilder = new StringBuilder("delete from student where id in (");
        DeleteParam deleteParam = new DeleteParam();
        deleteParam.setSql(sqlBuilder);
        deleteParam.setIds(ids);
        List<DeleteParam> list = new ArrayList();
        list.add(deleteParam);
        return this.doDelete(list);
    }

    public boolean update(StudentDO studentDO) {
        String sql = "update student set name = ?,no = ?,dept = ?,grade = ?, gender = ?, dormitory_id = ?  where id = ?";
        return this.doUpdate(sql, new Object[]{studentDO.getName(), studentDO.getNo(), studentDO.getDept(), studentDO.getGrade(), studentDO.getGender(), studentDO.getDormitoryId(), studentDO.getId()});
    }

    public TableResult<StudentDO> retrieveList(StudentRequest studentRequest) {
        TableResult<StudentDO> retDTO = new TableResult();
        StringBuilder sql = new StringBuilder();
        sql.append(" select s.id,s.name,s.gender,s.no,s.dept,s.grade, d.no as dormitoryNo,b.no as buildingNo,b.type ");
        this.appendFrom(sql);
        this.appendWhere(studentRequest, sql);
        sql.append(" order by s.id desc limit ");
        sql.append(studentRequest.getStart()).append(",").append(studentRequest.getPageSize());
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn != null) {
                ps = conn.prepareStatement(sql.toString());
                resultSet = ps.executeQuery();
                Vector data = new Vector();

                while(resultSet.next()) {
                    long id = resultSet.getLong("id");
                    String name = resultSet.getString("name");
                    String gender = resultSet.getString("gender");
                    String no = resultSet.getString("no");
                    String dept = resultSet.getString("dept");
                    String grade = resultSet.getString("grade");
                    String dormitoryNo = resultSet.getString("dormitoryNo");
                    String type = resultSet.getString("type");
                    String buildingNo = resultSet.getString("buildingNo");
                    StudentDO studentDO = new StudentDO();
                    studentDO.setId(id);
                    studentDO.setName(name);
                    studentDO.setGender(gender);
                    studentDO.setNo(no);
                    studentDO.setDept(dept);
                    studentDO.setGrade(grade);
                    studentDO.setDormitoryNo(dormitoryNo);
                    studentDO.setBuildingUniqueNo(BuildingDO.format(type, buildingNo));
                    data.addElement(studentDO);
                }

                sql.setLength(0);
                sql.append("select count(*) ");
                this.appendFrom(sql);
                this.appendWhere(studentRequest, sql);
                ps = conn.prepareStatement(sql.toString());
                resultSet = ps.executeQuery();

                while(resultSet.next()) {
                    int totalCount = resultSet.getInt(1);
                    retDTO.setTotalCount(totalCount);
                }

                retDTO.setData(data);
                retDTO.setPageNow(studentRequest.getpageNow());
                TableResult var20 = retDTO;
                return var20;
            }

            return null;
        } catch (SQLException var23) {
            var23.printStackTrace();
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return null;
    }

    public StudentDO retrieveOneById(Long id) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select s.id,s.name,s.gender,s.no,s.dept,s.grade,s.dormitory_id, d.dormitory_building_id  ");
        this.appendFrom(sql);
        sql.append(" where s.id =? ");
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet resultSet = null;

        try {
            if (conn != null) {
                ps = conn.prepareStatement(sql.toString());
                ps.setLong(1, id);
                resultSet = ps.executeQuery();
                StudentDO studentDO = new StudentDO();

                while(resultSet.next()) {
                    String no = resultSet.getString("no");
                    String name = resultSet.getString("name");
                    String gender = resultSet.getString("gender");
                    String dept = resultSet.getString("dept");
                    String grade = resultSet.getString("grade");
                    long dormitoryId = resultSet.getLong("dormitory_id");
                    long dormitoryBuildingId = resultSet.getLong("dormitory_building_id");
                    studentDO.setId(id);
                    studentDO.setName(name);
                    studentDO.setGender(gender);
                    studentDO.setNo(no);
                    studentDO.setDept(dept);
                    studentDO.setGrade(grade);
                    studentDO.setDormitoryId(dormitoryId);
                    studentDO.setBuildingId(dormitoryBuildingId);
                }

                StudentDO var17 = studentDO;
                return var17;
            }
        } catch (SQLException var20) {
            var20.printStackTrace();
            return null;
        } finally {
            DBUtil.closeResultSet(resultSet);
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return null;
    }

    private void appendFrom(StringBuilder sql) {
        sql.append(" from student s  ");
        sql.append(" left join dormitory d on s.dormitory_id = d.id  ");
        sql.append(" left join dormitory_building b on d.dormitory_building_id = b.id  ");
    }

    private void appendWhere(StudentRequest studentRequest, StringBuilder sql) {
        sql.append(" where 1=1 ");
        if (studentRequest.getStudentNo() != null && !"".equals(studentRequest.getStudentNo().trim())) {
            sql.append(" and s.no like '%");
            sql.append(studentRequest.getStudentNo());
            sql.append("%'");
        }

    }
}

service:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service;

import com.roadjava.studentroom.bean.dto.DeleteParam;
import com.roadjava.studentroom.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

public class BaseServiceSupport {
    public BaseServiceSupport() {
    }

    protected boolean doAdd(String sql, Object... args) {
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;

        try {
            if (conn == null) {
                return false;
            }

            ps = conn.prepareStatement(sql);
            this.populatePs(ps, args);
            boolean var7 = ps.executeUpdate() == 1;
            return var7;
        } catch (SQLException var10) {
            var10.printStackTrace();
        } finally {
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return false;
    }

    private void populatePs(PreparedStatement ps, Object... args) throws SQLException {
        if (args != null && args.length > 0) {
            for(int i = 0; i < args.length; ++i) {
                ps.setObject(i + 1, args[i]);
            }
        }

    }

    protected boolean doDelete(List<DeleteParam> deleteParams) {
        Connection conn = DBUtil.getConn();
        boolean result = true;

        try {
            conn.setAutoCommit(false);
            Iterator var5 = deleteParams.iterator();

            while(var5.hasNext()) {
                DeleteParam deleteParam = (DeleteParam)var5.next();
                StringBuilder sql = deleteParam.getSql();
                Long[] ids = deleteParam.getIds();
                int length = ids.length;

                for(int i = 0; i < length; ++i) {
                    if (i == length - 1) {
                        sql.append(" ?) ");
                    } else {
                        sql.append("?,");
                    }
                }

                PreparedStatement ps = null;

                try {
                    ps = conn.prepareStatement(sql.toString());

                    for(int i = 0; i < length; ++i) {
                        ps.setLong(i + 1, ids[i]);
                    }

                    System.out.println("ps:" + ps.toString());
                    ps.executeUpdate();
                } catch (SQLException var24) {
                    var24.printStackTrace();
                    conn.rollback();
                    result = false;
                    break;
                } finally {
                    DBUtil.closePs(ps);
                }
            }

            if (result) {
                conn.commit();
            }
        } catch (Exception var26) {
            result = false;
            var26.printStackTrace();

            try {
                conn.rollback();
            } catch (SQLException var23) {
                var23.printStackTrace();
                result = false;
            }
        } finally {
            DBUtil.closeConn(conn);
        }

        return result;
    }

    protected boolean doUpdate(String sql, Object... args) {
        Connection conn = DBUtil.getConn();
        PreparedStatement ps = null;

        try {
            if (conn != null) {
                ps = conn.prepareStatement(sql);
                this.populatePs(ps, args);
                boolean var7 = ps.executeUpdate() == 1;
                return var7;
            }
        } catch (SQLException var10) {
            var10.printStackTrace();
            return false;
        } finally {
            DBUtil.closePs(ps);
            DBUtil.closeConn(conn);
        }

        return false;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service;

import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.req.DormitoryBuildingRequest;
import com.roadjava.studentroom.res.TableResult;
import java.util.Vector;

public interface BuildingService {
    boolean add(BuildingDO var1);

    boolean delete(Long[] var1);

    boolean update(BuildingDO var1);

    TableResult<BuildingDO> retrieveList(DormitoryBuildingRequest var1);

    BuildingDO retrieveOneById(Long var1);

    Vector<BuildingDO> getVector(DormitoryBuildingRequest var1);
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service;

import com.roadjava.studentroom.bean.entity.DormitoryDO;
import com.roadjava.studentroom.req.DormitoryRequest;
import com.roadjava.studentroom.res.TableResult;
import java.util.Vector;

public interface DormitoryService {
    boolean add(DormitoryDO var1);

    boolean delete(Long[] var1);

    boolean update(DormitoryDO var1);

    TableResult<DormitoryDO> retrieveList(DormitoryRequest var1);

    DormitoryDO retrieveOneById(Long var1);

    Vector<DormitoryDO> getVector(DormitoryRequest var1);
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service;

import com.roadjava.studentroom.bean.entity.ManagerDO;

public interface ManagerService {
    boolean validateManagerInfo(ManagerDO var1);
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.service;

import com.roadjava.studentroom.bean.entity.StudentDO;
import com.roadjava.studentroom.req.StudentRequest;
import com.roadjava.studentroom.res.TableResult;

public interface StudentService {
    boolean add(StudentDO var1);

    boolean delete(Long[] var1);

    boolean update(StudentDO var1);

    TableResult<StudentDO> retrieveList(StudentRequest var1);

    StudentDO retrieveOneById(Long var1);
}

servlet:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.servlet;

import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.req.DormitoryBuildingRequest;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BuildingService;
import com.roadjava.studentroom.service.impl.BuildingServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "buildingServlet",
    urlPatterns = {"/building"}
)
public class BuildingServlet extends HttpServlet {
    BuildingService service = new BuildingServiceImpl();

    public BuildingServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("buildingActive", "active");
        String type = request.getParameter("type");
        String buildingId;
        String no;
        if ("toManage".equals(type)) {
            buildingId = request.getParameter("no");
            no = request.getParameter("pageNow");
            DormitoryBuildingRequest searchRequest = new DormitoryBuildingRequest();
            int pageNow = 1;
            if (no != null && !"".equals(no.trim())) {
                pageNow = Integer.parseInt(no);
            }

            searchRequest.setPageNow(pageNow);
            searchRequest.setNo(buildingId);
            TableResult<BuildingDO> tableResult = this.service.retrieveList(searchRequest);
            tableResult.setPageNow(pageNow);
            tableResult.setSearchWord(buildingId == null ? "" : buildingId);
            request.setAttribute("tableResult", tableResult);
            request.getRequestDispatcher("/WEB-INF/building/manage.jsp").forward(request, response);
        } else if ("toAdd".equals(type)) {
            request.getRequestDispatcher("/WEB-INF/building/add.jsp").forward(request, response);
        } else {
            String completedDate;
            if ("add".equals(type)) {
                buildingId = request.getParameter("no");
                no = request.getParameter("completedDate");
                completedDate = request.getParameter("buildingType");
                BuildingDO buildingDO = new BuildingDO();
                buildingDO.setNo(buildingId);
                buildingDO.setType(completedDate);
                buildingDO.setCompletedDate(no);
                this.service.add(buildingDO);
                response.sendRedirect(request.getContextPath() + "/building?type=toManage");
            } else if ("toUpdate".equals(type)) {
                buildingId = request.getParameter("id");
                no = request.getParameter("pageNow");
                BuildingDO buildingDO = this.service.retrieveOneById(Long.parseLong(buildingId));
                request.setAttribute("oneDO", buildingDO);
                request.setAttribute("pageNow", Integer.parseInt(no));
                request.getRequestDispatcher("/WEB-INF/building/update.jsp").forward(request, response);
            } else if ("update".equals(type)) {
                buildingId = request.getParameter("id");
                no = request.getParameter("no");
                completedDate = request.getParameter("completedDate");
                String buildingType = request.getParameter("buildingType");
                String pageNow = request.getParameter("pageNow");
                BuildingDO buildingDO = new BuildingDO();
                buildingDO.setId(Long.parseLong(buildingId));
                buildingDO.setNo(no);
                buildingDO.setType(buildingType);
                buildingDO.setCompletedDate(completedDate);
                this.service.update(buildingDO);
                response.sendRedirect(request.getContextPath() + "/building?type=toManage&pageNow=" + pageNow);
            } else if ("delete".equals(type)) {
                buildingId = request.getParameter("id");
                this.service.delete(new Long[]{Long.parseLong(buildingId)});
                response.sendRedirect(request.getContextPath() + "/building?type=toManage");
            }
        }

    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.servlet;

import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.bean.entity.DormitoryDO;
import com.roadjava.studentroom.req.DormitoryBuildingRequest;
import com.roadjava.studentroom.req.DormitoryRequest;
import com.roadjava.studentroom.res.ResultDTO;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BuildingService;
import com.roadjava.studentroom.service.DormitoryService;
import com.roadjava.studentroom.service.impl.BuildingServiceImpl;
import com.roadjava.studentroom.service.impl.DormitoryServiceImpl;
import com.roadjava.studentroom.util.ResponseUtil;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "dormitoryServlet",
    urlPatterns = {"/dormitory"}
)
public class DormitoryServlet extends HttpServlet {
    private DormitoryService service = new DormitoryServiceImpl();
    private BuildingService buildingService = new BuildingServiceImpl();

    public DormitoryServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("dormitoryActive", "active");
        String type = request.getParameter("type");
        String buildingId;
        String no;
        if ("toManage".equals(type)) {
            buildingId = request.getParameter("no");
            no = request.getParameter("pageNow");
            DormitoryRequest searchRequest = new DormitoryRequest();
            int pageNow = 1;
            if (no != null && !"".equals(no.trim())) {
                pageNow = Integer.parseInt(no);
            }

            searchRequest.setPageNow(pageNow);
            searchRequest.setNo(buildingId);
            TableResult<DormitoryDO> tableResult = this.service.retrieveList(searchRequest);
            tableResult.setPageNow(pageNow);
            tableResult.setSearchWord(buildingId == null ? "" : buildingId);
            request.setAttribute("tableResult", tableResult);
            request.getRequestDispatcher("/WEB-INF/dormitory/manage.jsp").forward(request, response);
        } else if ("toAdd".equals(type)) {
            DormitoryBuildingRequest dormitoryBuildingRequest = new DormitoryBuildingRequest();
            dormitoryBuildingRequest.setPageSize(-1);
            Vector<BuildingDO> vector = this.buildingService.getVector(dormitoryBuildingRequest);
            request.setAttribute("buildings", vector);
            request.getRequestDispatcher("/WEB-INF/dormitory/add.jsp").forward(request, response);
        } else {
            DormitoryDO dormitoryDO;
            if ("add".equals(type)) {
                buildingId = request.getParameter("no");
                no = request.getParameter("buildingId");
                dormitoryDO = new DormitoryDO();
                dormitoryDO.setNo(buildingId);
                dormitoryDO.setDormitoryBuildingId(Long.parseLong(no));
                this.service.add(dormitoryDO);
                response.sendRedirect(request.getContextPath() + "/dormitory?type=toManage");
            } else if ("toUpdate".equals(type)) {
                buildingId = request.getParameter("id");
                no = request.getParameter("pageNow");
                dormitoryDO = this.service.retrieveOneById(Long.parseLong(buildingId));
                request.setAttribute("oneDO", dormitoryDO);
                request.setAttribute("pageNow", Integer.parseInt(no));
                DormitoryBuildingRequest dormitoryBuildingRequest = new DormitoryBuildingRequest();
                dormitoryBuildingRequest.setPageSize(-1);
                Vector<BuildingDO> vector = this.buildingService.getVector(dormitoryBuildingRequest);
                request.setAttribute("buildings", vector);
                request.getRequestDispatcher("/WEB-INF/dormitory/update.jsp").forward(request, response);
            } else if ("update".equals(type)) {
                buildingId = request.getParameter("id");
                no = request.getParameter("no");
                String buildingId = request.getParameter("buildingId");
                String pageNow = request.getParameter("pageNow");
                DormitoryDO dormitoryDO = new DormitoryDO();
                dormitoryDO.setId(Long.parseLong(buildingId));
                dormitoryDO.setNo(no);
                dormitoryDO.setDormitoryBuildingId(Long.parseLong(buildingId));
                this.service.update(dormitoryDO);
                response.sendRedirect(request.getContextPath() + "/dormitory?type=toManage&pageNow=" + pageNow);
            } else if ("delete".equals(type)) {
                buildingId = request.getParameter("id");
                this.service.delete(new Long[]{Long.parseLong(buildingId)});
                response.sendRedirect(request.getContextPath() + "/dormitory?type=toManage");
            } else if ("getDormitoriesByBuildingId".equals(type)) {
                buildingId = request.getParameter("buildingId");
                DormitoryRequest dormitoryRequest = new DormitoryRequest();
                dormitoryRequest.setPageSize(-1);
                dormitoryRequest.setDormitoryBuildingId(Long.parseLong(buildingId));
                Vector<DormitoryDO> dormitoryDOS = this.service.getVector(dormitoryRequest);
                ResponseUtil.respAppJson(response, ResultDTO.buildSuccess(dormitoryDOS));
            }
        }

    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.servlet;

import com.roadjava.studentroom.bean.entity.ManagerDO;
import com.roadjava.studentroom.res.ResultDTO;
import com.roadjava.studentroom.service.ManagerService;
import com.roadjava.studentroom.service.impl.ManagerServiceImpl;
import com.roadjava.studentroom.util.ResponseUtil;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "loginServlet",
    urlPatterns = {"/loginServlet"}
)
public class LoginServlet extends HttpServlet {
    ManagerService managerService = new ManagerServiceImpl();

    public LoginServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String type = request.getParameter("type");
        if ("trueLogin".equals(type)) {
            String uname = request.getParameter("uname");
            String pwd = request.getParameter("pwd");
            if (uname == null || "".equals(uname.trim()) || pwd == null || "".equals(pwd.trim())) {
                ResultDTO<Object> dto = ResultDTO.buildFailure("用户名或密码不能为空");
                ResponseUtil.respAppJson(response, dto);
                return;
            }

            ManagerDO managerDO = new ManagerDO();
            managerDO.setUserName(uname);
            managerDO.setPwd(pwd);
            boolean b = this.managerService.validateManagerInfo(managerDO);
            if (b) {
                request.getSession().setAttribute("manager", managerDO);
                ResponseUtil.respAppJson(response, ResultDTO.buildEmptySuccess());
            } else {
                ResponseUtil.respAppJson(response, ResultDTO.buildFailure("用户名或密码不正确"));
            }
        } else {
            request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response);
        }

    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.servlet;

import com.roadjava.studentroom.service.ManagerService;
import com.roadjava.studentroom.service.impl.ManagerServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "managerServlet",
    urlPatterns = {"/manager"}
)
public class ManagerServlet extends HttpServlet {
    ManagerService managerService = new ManagerServiceImpl();

    public ManagerServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("managerActive", "active");
        String type = request.getParameter("type");
        if ("logout".equals(type)) {
            request.getSession().invalidate();
            response.sendRedirect(request.getContextPath() + "/index.jsp");
        }

    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.servlet;

import com.roadjava.studentroom.bean.entity.BuildingDO;
import com.roadjava.studentroom.bean.entity.StudentDO;
import com.roadjava.studentroom.req.DormitoryBuildingRequest;
import com.roadjava.studentroom.req.StudentRequest;
import com.roadjava.studentroom.res.ResultDTO;
import com.roadjava.studentroom.res.TableResult;
import com.roadjava.studentroom.service.BuildingService;
import com.roadjava.studentroom.service.DormitoryService;
import com.roadjava.studentroom.service.StudentService;
import com.roadjava.studentroom.service.impl.BuildingServiceImpl;
import com.roadjava.studentroom.service.impl.DormitoryServiceImpl;
import com.roadjava.studentroom.service.impl.StudentServiceImpl;
import com.roadjava.studentroom.util.ResponseUtil;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "studentServlet",
    urlPatterns = {"/student"}
)
public class StudentServlet extends HttpServlet {
    private StudentService service = new StudentServiceImpl();
    private DormitoryService dormitoryService = new DormitoryServiceImpl();
    private BuildingService buildingService = new BuildingServiceImpl();

    public StudentServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("studentActive", "active");
        String type = request.getParameter("type");
        String id;
        String pageNow;
        if ("toManage".equals(type)) {
            id = request.getParameter("no");
            pageNow = request.getParameter("pageNow");
            StudentRequest searchRequest = new StudentRequest();
            int pageNow = 1;
            if (pageNow != null && !"".equals(pageNow.trim())) {
                pageNow = Integer.parseInt(pageNow);
            }

            searchRequest.setPageNow(pageNow);
            searchRequest.setStudentNo(id);
            TableResult<StudentDO> tableResult = this.service.retrieveList(searchRequest);
            tableResult.setPageNow(pageNow);
            tableResult.setSearchWord(id == null ? "" : id);
            request.setAttribute("tableResult", tableResult);
            request.getRequestDispatcher("/WEB-INF/student/manage.jsp").forward(request, response);
        } else if ("toAdd".equals(type)) {
            DormitoryBuildingRequest dormitoryBuildingRequest = new DormitoryBuildingRequest();
            dormitoryBuildingRequest.setPageSize(-1);
            Vector<BuildingDO> vector = this.buildingService.getVector(dormitoryBuildingRequest);
            request.setAttribute("buildings", vector);
            request.getRequestDispatcher("/WEB-INF/student/add.jsp").forward(request, response);
        } else if ("add".equals(type)) {
            try {
                StudentDO studentDO = this.buildBasicStudent(request);
                boolean b = this.service.add(studentDO);
                if (b) {
                    ResponseUtil.respAppJson(response, ResultDTO.buildSuccess("添加成功"));
                } else {
                    ResponseUtil.respAppJson(response, ResultDTO.buildFailure("添加失败"));
                }
            } catch (Exception var10) {
                var10.printStackTrace();
                ResponseUtil.respAppJson(response, ResultDTO.buildFailure(var10.getMessage()));
            }
        } else if ("toUpdate".equals(type)) {
            id = request.getParameter("id");
            pageNow = request.getParameter("pageNow");
            StudentDO dormitoryDO = this.service.retrieveOneById(Long.parseLong(id));
            request.setAttribute("oneDO", dormitoryDO);
            request.setAttribute("pageNow", Integer.parseInt(pageNow));
            DormitoryBuildingRequest dormitoryBuildingRequest = new DormitoryBuildingRequest();
            dormitoryBuildingRequest.setPageSize(-1);
            Vector<BuildingDO> vector = this.buildingService.getVector(dormitoryBuildingRequest);
            request.setAttribute("buildings", vector);
            request.getRequestDispatcher("/WEB-INF/student/update.jsp").forward(request, response);
        } else if ("update".equals(type)) {
            try {
                id = request.getParameter("id");
                StudentDO studentDO = this.buildBasicStudent(request);
                studentDO.setId(Long.parseLong(id));
                boolean b = this.service.update(studentDO);
                if (b) {
                    ResponseUtil.respAppJson(response, ResultDTO.buildSuccess("更新成功"));
                } else {
                    ResponseUtil.respAppJson(response, ResultDTO.buildFailure("更新失败"));
                }
            } catch (Exception var9) {
                var9.printStackTrace();
                ResponseUtil.respAppJson(response, ResultDTO.buildFailure(var9.getMessage()));
            }
        } else if ("delete".equals(type)) {
            id = request.getParameter("id");
            this.service.delete(new Long[]{Long.parseLong(id)});
            response.sendRedirect(request.getContextPath() + "/student?type=toManage");
        }

    }

    private StudentDO buildBasicStudent(HttpServletRequest request) {
        String no = request.getParameter("no");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        String dept = request.getParameter("dept");
        String grade = request.getParameter("grade");
        String dormitoryId = request.getParameter("dormitoryId");
        StudentDO studentDO = new StudentDO();
        studentDO.setNo(no);
        studentDO.setName(name);
        studentDO.setGender(gender);
        studentDO.setDept(dept);
        studentDO.setGrade(grade);
        studentDO.setDormitoryId(Long.parseLong(dormitoryId));
        return studentDO;
    }
}

util:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.util;

import java.util.Date;

public class Constants {
    public static final Integer PAGE_SIZE = 10;
    public static final String MIDDLE_LINE = "-";

    public Constants() {
    }

    public static void main(String[] args) {
        Date date = new Date();
        System.out.println(date);
        System.out.println(date.getTime());
        System.out.println(System.currentTimeMillis());
    }
}

  // IntelliJ API Decompiler stub source generated from a class file
  // Implementation of methods is not available

package com.roadjava.studentroom.util;

public class DBUtil {
    private static final java.lang.String URL = "jdbc:mysql://localhost:3306/dormitory?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false";
    private static final java.lang.String DRIVER = "com.mysql.jdbc.Driver";
    private static final java.lang.String USER_NAME = "输入自己的数据库名";
    private static final java.lang.String PWD = "输入自己的数据库密码";

    public DBUtil() { /* compiled code */ }

    public static java.sql.Connection getConn() { /* compiled code */ }

    public static void closeResultSet(java.sql.ResultSet resultSet) { /* compiled code */ }

    public static void closePs(java.sql.PreparedStatement ps) { /* compiled code */ }

    public static void closeConn(java.sql.Connection conn) { /* compiled code */ }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.roadjava.studentroom.util;

import com.alibaba.fastjson.JSON;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;

public class ResponseUtil {
    public ResponseUtil() {
    }

    public static void respTxtHtml(HttpServletResponse resp, String result) {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        write(resp, result);
    }

    private static void write(HttpServletResponse resp, String result) {
        try {
            Throwable var2 = null;
            Object var3 = null;

            try {
                PrintWriter writer = resp.getWriter();

                try {
                    writer.print(result);
                    writer.flush();
                } finally {
                    if (writer != null) {
                        writer.close();
                    }

                }
            } catch (Throwable var12) {
                if (var2 == null) {
                    var2 = var12;
                } else if (var2 != var12) {
                    var2.addSuppressed(var12);
                }

                throw var2;
            }
        } catch (IOException var13) {
            var13.printStackTrace();
        }

    }

    public static void respTxtPlain(HttpServletResponse resp, String result) {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/plain;charset=utf-8");
        write(resp, result);
    }

    public static void respAppJson(HttpServletResponse resp, Object obj) {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        write(resp, JSON.toJSONString(obj));
    }
}

7.Mysql模块:

7.1 dormitory:

7.2 dormitory_building:

7.3 manager:

7.4 student:

7.5 MySql代码:

DROP TABLE IF EXISTS `dormitory`;
CREATE TABLE `dormitory` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `no` varchar(50) NOT NULL COMMENT '宿舍编号',
  `dormitory_building_id` bigint(20) NOT NULL COMMENT '外键,宿舍所在楼id',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of dormitory
-- ----------------------------
INSERT INTO `dormitory` VALUES ('1', '11', '3');
INSERT INTO `dormitory` VALUES ('2', '12', '3');
INSERT INTO `dormitory` VALUES ('3', '13', '3');
INSERT INTO `dormitory` VALUES ('4', '14', '3');
INSERT INTO `dormitory` VALUES ('5', '14', '2');

-- ----------------------------
-- Table structure for dormitory_building
-- ----------------------------
DROP TABLE IF EXISTS `dormitory_building`;
CREATE TABLE `dormitory_building` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `no` varchar(50) NOT NULL COMMENT '宿舍楼编号',
  `completed_date` date NOT NULL COMMENT '宿舍楼建成时间',
  `type` char(1) NOT NULL COMMENT '宿舍楼类型:M:男生宿舍,F:女生宿舍',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of dormitory_building
-- ----------------------------
INSERT INTO `dormitory_building` VALUES ('1', '1', '2022-07-16', 'M');
INSERT INTO `dormitory_building` VALUES ('2', '2', '2022-07-07', 'M');
INSERT INTO `dormitory_building` VALUES ('3', '3', '2022-07-14', 'F');

-- ----------------------------
-- Table structure for manager
-- ----------------------------
DROP TABLE IF EXISTS `manager`;
CREATE TABLE `manager` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `user_name` varchar(50) NOT NULL COMMENT '登录用户名',
  `pwd` varchar(50) NOT NULL COMMENT '密码',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='管理员表';

-- ----------------------------
-- Records of manager
-- ----------------------------
INSERT INTO `manager` VALUES ('1', 'admin', 'admin');

-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `no` varchar(50) NOT NULL COMMENT '学号',
  `name` varchar(50) NOT NULL COMMENT '学生姓名',
  `gender` char(1) NOT NULL COMMENT '性别:M:男,F:女',
  `dept` varchar(100) NOT NULL COMMENT '院系',
  `grade` varchar(100) NOT NULL COMMENT '班级',
  `dormitory_id` bigint(20) NOT NULL COMMENT '外键,宿舍id',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_no` (`no`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ('1', '1001', '冰墩墩', 'M', 'jisuanji', '1', '5');
INSERT INTO `student` VALUES ('2', '1003', 'wangmeili', 'F', '化学系', '111', '4');
INSERT INTO `student` VALUES ('3', '1002', '王大锤', 'M', '化学系', '111', '5');

注:项目根据王不二实战项目

标签: java maven tomcat

本文转载自: https://blog.csdn.net/weixin_61684487/article/details/127494395
版权归原作者 狐狸先森。 所有, 如有侵权,请联系我们删除。

“学生宿舍管理系统”的评论:

还没有评论