首页>代码>基于JavaWeb的酒店管理系统>/源代码/HotelSys/src/com/inks/hb/authinfo/controller/AuthInfoServlet.java
package com.inks.hb.authinfo.controller;

import com.google.gson.Gson;
import com.inks.hb.authinfo.pojo.AuthInfo;
import com.inks.hb.authinfo.service.AuthService;
import com.inks.hb.authinfo.service.AuthServiceImpl;
import com.inks.hb.common.PojotoGson;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 分页查询权限表
 * 如查询过程中出现异常,统一返回'数据查询出现异常'
 * 返回数据为pojotoGson类型
 */
@WebServlet(value = "/AuthInfoServlet", name = "AuthInfoServlet")
public class AuthInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        int page = Integer.parseInt(request.getParameter("page")); // 当前页码
        int limit = Integer.parseInt(request.getParameter("limit")); // 每页的数据量
        int make = Integer.parseInt(request.getParameter("make"));

        // 调用service
        AuthService service = new AuthServiceImpl();

        // 默认输出信息
        String code = "0"; //状态码
        String msg = "数据查询正常"; //状态信息
        String count = ""; //数据总数
        ArrayList<AuthInfo> list = new ArrayList<>(); //数据内容

        //单个全局属性
        int authId;                  //权限ID
        String authItem = "";        //权限名称
        String isRead;               //可读
        String isWrite;              //可写
        String isChange;             //可改
        String isDelete;             //可删
        AuthInfo authInfo = null;

        try {

            // 状态标志 make 0重载 1新增 2修改 3搜索 4删除
            if (make == 2) {
                authId = Integer.parseInt(request.getParameter("authId"));
                authItem = request.getParameter("authItem");
                isRead = request.getParameter("isRead");
                isWrite = request.getParameter("isWrite");
                isChange = request.getParameter("isChange");
                isDelete = request.getParameter("isDelete");
                authInfo = new AuthInfo(authId, authItem, isRead, isWrite, isChange, isDelete);
            } else if (make == 3) {
                authItem = request.getParameter("authItem");
            }

            switch (make) {
                case 2:
                    service.updateAuthInfo(authInfo);
                    break;
                case 3:
                    authInfo = service.query(authItem);
                    list.clear();
                    list.add(authInfo);
                    break;
            }
            if (make != 3) {
                list = service.query(page, limit);
                count = String.valueOf(service.queryAuthInfoNum());
            } else {
                if (authInfo.getAuthId() == 0) {
                    count = "0";
                } else {
                    count = "1";
                }
            }
        } catch (SQLException e) {
            code = "1";
            msg = "数据查询出现异常";
            e.printStackTrace();
        } finally {
            PojotoGson pojotoGson = new PojotoGson(code, msg, count, list);
            Gson gson = new Gson();
            out.print(gson.toJson(pojotoGson));
        }
    }
}
最近下载更多
qiang123  LV8 4月13日
qq1357574774  LV2 3月28日
qqFFFFF  LV8 3月25日
wanglinddad  LV55 3月1日
妈妈妈妈妈妈  LV8 1月29日
1297807492  LV6 1月23日
woshiwo  LV3 1月17日
xiaoyu111ewsd  LV4 1月16日
最近浏览更多
kenhomeliu  LV29 4月30日
12345644 4月29日
暂无贡献等级
102404426  LV7 4月21日
Zzzzzzzzz66  LV1 4月20日
Boss绝  LV9 4月19日
可是不知道么  LV23 4月17日
op123129 4月15日
暂无贡献等级
justinleo  LV1 4月14日
qiang123  LV8 4月13日
lo8lukoukoum  LV4 4月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友